Reputation: 345
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 become irrelevant.
Upvotes: 3
Views: 16233
Reputation: 313
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 comment 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 common problem. Use the Find tool in a text editor to help find typos.
Upvotes: 4
Reputation:
There's a
Attachment
class in discord.js. So, it will create a conflict between variables definitions. You should rename it to something else!
Upvotes: 3