成员角色命令

时间:2018-02-16 17:23:55

标签: python discord discord.py

所以我一直试图获得这个命令$ 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'

1 个答案:

答案 0 :(得分:0)

协程名为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")

假设messageuserchannel已正确定义。

如果您正在撰写大量此类命令,则应考虑使用discord.ext.commands扩展名,这意味着您不必将所有命令保留在{{{ 1}}事件。

相关问题