我需要從消息中獲取圖片,如果它在那里我使用重寫版本我試過這個:message.attachments[0]['url']但得到一個錯誤 Ignoring exception in on_messageTraceback (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>我怎樣才能得到圖片網址?
1 回答

RISEBY
TA貢獻1856條經驗 獲得超5個贊
可以直接從對象中獲取 url 屬性
message.attachments[0].url
基本上,錯誤說的是這個對象沒有實現__getitem__
,這意味著你不能[i]
在它上面使用。
添加回答
舉報
0/150
提交
取消