【问题标题】:How to make a discord bot only rspond to a command from a certain rank [duplicate]如何使不和谐的机器人只响应某个等级的命令[重复]
【发布时间】:2020-07-30 05:21:08
【问题描述】:

我的服务器上已经有一个使用 python 的不和谐机器人,任何人都可以加入我的服务器并使用该机器人,但我只希望我们的 mods 角色能够使用特定的命令。因此,如果有人刚刚进入服务器,他们不能使用显示一堆只有 mod 才能看到的信息的命令,但可以使用与他们一起玩琐事或其他东西的命令。

【问题讨论】:

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


    【解决方案1】:

    你可以使用装饰器@has_permission

    import discord
    from discord.ext.commands import has_permission
    
    @bot.command(pass_context=True)
    @has_permission(administrator=True)
    async def some_command(ctx):
        # something to do.
    

    有多种权限,您可以在here 看到它们。所有@property都可以作为权限使用。

    【讨论】:

      【解决方案2】:

      您实际上可以通过上下文访问消息作者的角色。

      这是一个例子:

      async def command_for_mods(ctx, further_arguments):
          if "moderator" in [i.name.lower() for i in ctx.author.roles]:
              # Do things only moderators can do
          else:
              # Tell the user they don't have the moderator role or pass
      

      如果有任何错误,请告诉我,因为我可能不准确。

      【讨论】:

        猜你喜欢
        • 2021-06-17
        • 1970-01-01
        • 2021-11-21
        • 2021-09-12
        • 2021-08-26
        • 2018-11-10
        • 2021-11-10
        • 2018-07-21
        • 2021-08-03
        相关资源
        最近更新 更多