我需要从消息中获取图片,如果它在那里我使用重写版本
我试过这个:
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)
我怎样才能得到图片网址?
我正在尝试编写一个机器人程序,当用户键入“b.assemble”时,它会为用户提供“管理员”角色,但我不断收到此错误:
discord.ext.commands.errors.CommandInvokeError:
AttributeError: 'Context' object has no attribute 'guild'
Run Code Online (Sandbox Code Playgroud)
调用错误的部分如下所示:
guild = ctx.guild
await guild.create_role(name="Admin")
role = discord.utils.get(ctx.guild.roles, name="Admin")
user = ctx.message.author
await user.add_roles(role)
Run Code Online (Sandbox Code Playgroud) 机器人必须每 60 秒执行一次操作。我尝试使用 create_task,但它不起作用(机器人启动但没有任何反应)。如何实施?