从消息中获取图片

Get a picture from the message

如果有消息,我需要从消息中获取图片 我用重写的版本

我试过这个:

message.attachments[0]['url']

但是出现错误

    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

如果您只留下索引或附件,您会得到:

<discord.message.Attachment object at 0x00000228B8E3BE80>

如何获取图像 url?

可以直接从对象中得到url属性

message.attachments[0].url

基本上,错误说明该对象没有实现 __getitem__,这意味着您不能在其上使用 [i]