【发布时间】:2020-12-08 09:18:48
【问题描述】:
我正在尝试为我的机器人创建一个 DM 帮助命令,该命令会根据我添加的命令数量自动生成。我希望它省略带有guild_only 检查的命令。
这是我的代码:
import discord
from discord.ext import commands
...
...
# Imagine that in this case, `command` is a command with the `guild_only` check.
# This is in a much larger for loop
if commands.guild_only not in command.checks:
# add command to string of commands
help_c = ''.join([help_c, f"`{ctx.prefix}{command.name}{brief}`"
f"{separate_into_aliases(command)}\n{desc}\n\n"])
我假设 commands.guild_only not in command.checks 会返回 False,因为 guild_only 检查 is 在检查列表中。但它没有。
这是带有guild_only的命令的检查属性列表返回:
[<function guild_only.<locals>.predicate at 0x04A60150>]
这里是commands.guild_only:
<function guild_only at 0x0481F150>
两者相似但不相同。
我的问题是如何检查命令是否在其checks 属性中检查了guild_only?
【问题讨论】:
标签: python python-3.x function discord.py discord.py-rewrite