Skip to content
Advertisement

Getting an error when trying to get an attachment url in discord.py

I’m trying to make a discord bot that would repost art submissions to the art channel after they are approved by the moderators. Every time I try to extract the attachment URL, I get this error:

JavaScript

I tried searching this up on the Internet, but there is nothing. The only thing I found was this post, but I did everything right. Can someone explain to me what’s happening? My code:

JavaScript

Also, I tried to use message.attachments[0].url but got the same thing

Advertisement

Answer

This can be appear for some reasons:

  1. Your bot don’t check for attachments at all, so if user will send messages without image in it, bot will crash
  2. You don’t check who sended message and where (for example, bot can reply on it’s own message or on message which isn’t from #arts-request channel)
  3. You should use url attribute, to get image url for embed

So the final code will look like this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement