首页 > 解决方案 > Discord.py 根据空设置检查条件

问题描述

我有一个准备好通过 Heroku 以及普通 Python 部署的 Bot。我在其 app.json 以及 settings.json 中添加了roles_id,可以与普通主机一起使用。我目前通过 has_role(ROLE_ID) 对所有命令进行条件检查并执行命令。我想补充一下,如果设置中没有提到 role_id,它应该自动使用 is_owner() 检查。

@bot.command(name='test', aliases=['tst'])
@commands.has_role(ROLE_ID)
async def _test(ctx):

现在我想对我的所有命令使用条件检查,如果没有提到角色 ID 或在其环境中为空,它应该自动使用 is_owner 函数进行检查。

标签: pythonpython-3.xdiscord.pydiscord.py-rewrite

解决方案


你可以check_any

from discord.ext import commands

@bot.command(name='test', aliases=['tst'])
@commands.check_any(commands.has_role(ROLE_ID), commands.is_owner())
async def _test(ctx):
    ...

推荐阅读