admin管理员组

文章数量:1291024

I just want to use my Discord.JS bot to get the first attachment in a message (MessageAttatchment object), simply put. I have already tried this, but it just seems to crash immediately.

  var Attachment = (message.attachments)
  if (Attatchment){
    console.log( Attatchment.array()[0] )
    console.log( Attatchment.array()[0].url )
  }

The crash might not be due to this, it could be due to relevant code surrounding the area, but this is not a problem, since if I find a solution, that relevant code will bee irrelevant.

I just want to use my Discord.JS bot to get the first attachment in a message (MessageAttatchment object), simply put. I have already tried this, but it just seems to crash immediately.

  var Attachment = (message.attachments)
  if (Attatchment){
    console.log( Attatchment.array()[0] )
    console.log( Attatchment.array()[0].url )
  }

The crash might not be due to this, it could be due to relevant code surrounding the area, but this is not a problem, since if I find a solution, that relevant code will bee irrelevant.

Share Improve this question asked Dec 19, 2018 at 2:40 Wasabi ThumbsWasabi Thumbs 3451 gold badge3 silver badges8 bronze badges 2
  • 2 You seem to have misspelt Attachment in most of your code. – Nick Commented Dec 19, 2018 at 2:47
  • Well, that might fix things...! Let me try that! – Wasabi Thumbs Commented Dec 20, 2018 at 3:41
Add a ment  | 

2 Answers 2

Reset to default 4

I know this is 2 years old, but I think I might of found the problem. You seem to have mistyped the variable attachment, instead of attachment, you types in attatchment.

This is how the code should look like. Although, not sure if there may be more errors, this code snippet just fixes the typos.

var Attachment = (message.attachments)
if (Attachment){
    console.log( Attachment.array()[0] )
    console.log( Attachment.array()[0].url )
}

There is a ment on it that does point it out, but they haven't considered it as an answer.

Tip: Always try to check for typos in your code, that is the most mon problem. Use the Find tool in a text editor to help find typos.

There's a Attachment class in discord.js. So, it will create a conflict between variables definitions. You should rename it to something else!

本文标签: javascriptDiscordJS Get First Attachment in MessageStack Overflow