,所以我一直在尝试获得此命令$ 100ivshiny,以使我的成员实际等级100ivshiny。但是我似乎找不到解决方案。
if message.content.startswith('$100ivShiny'):
role = discord.utils.get(message.server.roles, name="100ivShiny")
await client.add_role(user, role)
await client.send_message(channel, "Role added")
这是我遇到的错误
File "mod.py", line 29, in on_message
await client.add_role(user, role)
AttributeError: '<class 'discord.client.Client'>' object has no attribute 'add_role'
coroutine命名为 Client.add_roles
,而不是 Client.add_role
。它会像
if message.content.startswith('$100ivShiny'):
role = discord.utils.get(message.server.roles, name="100ivShiny")
await client.add_roles(user, [role])
await client.send_message(channel, "Role added")
假设message
,user
和channel
适当定义。
如果您正在编写许多这样的命令,则应考虑使用discord.ext.commands
扩展名,这意味着您不必将所有命令保留在on_message
事件中。