Discord.py 根据空设置检查条件
Discord.py Checks with Conditions based on empty settings
我有一个 Bot 准备好通过 Heroku 和正常部署 Python。我已经在它的 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):
现在我想对我的所有命令使用条件检查,如果 roles_id 在其环境中未被提及或为空,它应该自动使用 is_owner 函数进行检查。
你可以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):
...
我有一个 Bot 准备好通过 Heroku 和正常部署 Python。我已经在它的 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):
现在我想对我的所有命令使用条件检查,如果 roles_id 在其环境中未被提及或为空,它应该自动使用 is_owner 函数进行检查。
你可以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):
...