Discord.JS Get First Attachment in Message

11,433

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.

Share:
11,433
Wasabi Thumbs
Author by

Wasabi Thumbs

Updated on June 05, 2022

Comments

  • Wasabi Thumbs
    Wasabi Thumbs almost 2 years

    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.

  • Wasabi Thumbs
    Wasabi Thumbs almost 3 years
    Yes, that was the solution, lol... in my past naïveté I somehow did not consider typos as a possible issue, and I figured that was so boldly apparent that I didn't need to mark an answer as correct. Anyways, great response, I hope you keep giving advice to other users on the platform!
  • Jonathan J. Pecany
    Jonathan J. Pecany almost 3 years
    I'll try my best to give advice to other users.