【问题标题】:How to check if the command user has a specific role in discord?如何检查命令用户是否在不和谐中具有特定角色?
【发布时间】:2021-06-11 12:47:57
【问题描述】:

所以我正在制作一个不和谐的机器人,但我不想让某些命令只能由特定角色使用 代码如下:

 @client.command()
async def mute(ctx,member : discord.Member):
 
  muted_role = ctx.guild.get_role(I don't know if i should share this role id so just imagine there is a role id here)

  await member.add_roles(muted_role)

  await ctx.send(member.mention + " has been muted")

【问题讨论】:

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


    【解决方案1】:

    您可以简单地使用 has_role 装饰器

    @client.command()
    @commands.has_role(198723981723) # Or the role name
    async def mute(ctx, member: discord.Member):
    

    参考:

    【讨论】:

    • 如果有帮助记得采纳答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 2010-12-22
    • 2019-06-16
    • 2016-05-02
    • 2018-11-06
    相关资源
    最近更新 更多