python - 如何检查discord.py中的所有者

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

我正在尝试使该命令只有所有者才能运行。是否有办法检查服务器的最高角色或创建者?

我尝试了“@commands.is_owner()”,但这仅检查某人是否是机器人的所有者。

最佳答案

Guild.owner存在,所以这里是它的使用示例!

from discord.ext import commands


bot = commands.Bot(command_prefix="your_prefix")

# example use with custom decorator
def guild_owner_only():
    async def predicate(ctx):
        return ctx.author == ctx.guild.owner  # checks if author is the owner

    return commands.check(predicate)

@bot.command()
@guild_owner_only()
async def ...

关于python - 如何检查discord.py中的所有者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67036585/

相关文章:

python - 无法让我的脚本只从一个顽固的网站获取下一页的链接

python - 等待语句不输出消息

python - 根据需要在字符串之间添加文本

python - 如何将自定义错误代码添加到 Django Rest Framework

python - 试图理解 Python 的 Concurrent.Futures 模块

python - Discord PY Bot react 后崩溃

javascript - 通过 Discord OAuth 传递字符串?

python - TensorFlow keras 模型 fit() 参数 steps_per_epoch 和 epochs 在训练集上的行为

python - 如何在 Django 管理表单中添加自定义操作按钮并发布信息

python - config.from_object 在使用 Python 3 的 Flask 中不起作用