【问题标题】:Get a picture from the message从消息中获取图片
【发布时间】:2019-08-07 23:18:14
【问题描述】:

如果有的话,我需要从消息中获取图片 我用的是改写版

我试过了:

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>

如何获取图片地址?

【问题讨论】:

  • 显然[] 不是从附件对象获取信息的正确方法。也许你应该检查它的属性。

标签: python python-3.x discord discord.py discord.py-rewrite


【解决方案1】:

可以直接从对象中获取url属性

message.attachments[0].url

基本上,错误说的是这个对象没有实现__getitem__,这意味着你不能在它上面使用[i]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    相关资源
    最近更新 更多