简体   繁体   English

成员角色命令

[英]Members role command

so i been trying to get this command $100ivShiny to give my members the actual rank 100ivShiny. 因此,我一直在尝试获取此命令$ 100ivShiny,以使我的成员实际排名为100ivShiny。 but i cant seem to find the solution. 但我似乎找不到解决方案。

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")

this is the error i'm getting 这是我得到的错误

  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'

The coroutine is named Client.add_roles , not Client.add_role . 协程名为Client.add_roles ,而不是Client.add_role It would be used like 它会像

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")

Assuming message , user , and channel are defined appropriately. 假设messageuserchannel被适当定义。

If you're writing a lot of commands like this, you should look into using the discord.ext.commands extension, it means that you don't have to keep all of your commands in the on_message event. 如果要编写很多这样的命令,则应使用discord.ext.commands扩展名进行研究,这意味着您不必将所有命令都保留在on_message事件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM