python - 角色特定命令

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

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

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

最佳答案

您可以使用 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))

关于python - 角色特定命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50505434/

相关文章:

python 2.7 : how to read only a few lines at a time from a file?

python - 按下按钮时有多个命令

python - 从 csv 读取的数据出现 ValueError : setting an array element with a sequence.

Python格式电话号码

Python:通用/模板化 getter

python - 我的 discord 机器人从 youtube url 播放音频时遇到问题

node.js - 需要帮助在我的 Discord 机器人上配置加入消息

python - 程序忽略 if 语句,并在 False 时打印 True

python - Python 字典文字和字典(成对列表)是否保持其键顺序?

node.js - 将 Heroku Webhooks 与 Discord 连接