I need to get a picture from the message if it is there I use rewritten version
I tried this:
message.attachments[0]['url']
But getting an error
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\vlad0\AppData\Roaming\Python\Python36\site-packages\discord\client.py", line 227, in _run_event
await coro(*args, **kwargs)
File "c:\Users\vlad0\Desktop\bot\bot.py", line 121, in on_message
print(message.attachments[0]['url'])
TypeError: 'Attachment' object is not subscriptable
If you leave only the index or only attachments, you get this:
<discord.message.Attachment object at 0x00000228B8E3BE80>
How can i get image url?
You can directly get the url property from the object
message.attachments[0].url
Basically, what the error says is that this object does not implement the __getitem__
, which means you can't use [i]
on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With