Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a picture from the message

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?

like image 713
Buzzard Avatar asked Jan 27 '23 14:01

Buzzard


1 Answers

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.

like image 158
jgoday Avatar answered Feb 11 '23 19:02

jgoday