python - 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 函数进行检查。
解决方案
你可以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):
...
推荐阅读
- jquery - 更改悬停时的图像
- amazon-web-services - 查询 DynamoDB 预置吞吐量 WCU/RCU 操作
- mysql - 修复 Mysql 计数器中的空白
- opengl - OpenGL Resize Window -> 对象被“移动/翻译”
- javascript - 单击链接后使用 jQuery 加载图像
- python - Python - 将巨大的数组排序为多个
- java - 两个不同实体中的相同@NamedQueries 会发出警告
- javascript - 更改所选选项的背景颜色
- javascript - 如何下载从 papaparse 生成的 csv?
- c# - 将解决方案更新到 .NET 4.7.2 时,MSBuild 失败