首页 文章

角色特定命令

提问于
浏览
1

角色特定命令是的,它的工作终于得到了它 .

from discord.ext import commands

bot = commands.Bot('?')

@bot.command(pass_context=True)
@commands.has_any_role("Admin", "Moderator")
async def hello(ctx):
    await bot.say("Hello {}".format(ctx.message.author.mention))

1 回答

  • 1

    您可以使用 discord.ext.commands 扩展名,它提供has_any_role装饰器 .

    from discord.ext import commands
    
    bot = commands.Bot('?')
    
    @bot.command(pass_context=True)
    @commands.has_any_role("Admin", "Moderator")
    async def hello(ctx):
        await bot.say("Hello {}".format(ctx.message.author.mention))
    

相关问题