Buz*_*ard 4 python python-3.x discord discord.py discord.py-rewrite
我需要从消息中获取图片,如果它在那里我使用重写版本
我试过这个:
message.attachments[0]['url']
Run Code Online (Sandbox Code Playgroud)
但得到一个错误
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
Run Code Online (Sandbox Code Playgroud)
如果你只留下索引或只留下附件,你会得到这个:
<discord.message.Attachment object at 0x00000228B8E3BE80>
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到图片网址?
可以直接从对象中获取 url 属性
message.attachments[0].url
Run Code Online (Sandbox Code Playgroud)
基本上,错误说的是这个对象没有实现__getitem__,这意味着你不能[i]在它上面使用。
| 归档时间: |
|
| 查看次数: |
6468 次 |
| 最近记录: |