【发布时间】:2020-12-23 17:47:35
【问题描述】:
我有一个 Discord 机器人,我试图将默认帮助命令的帮助与其他命令的帮助归入同一类别。当我什么都不做时,默认的帮助命令会显示:
ChatNote: note Adds a note to a notebook No Category: help Shows this message
然后我根据另一个 SO answer 尝试这段代码:
bot = commands.Bot(command_prefix="##", case_insensitive=True, name="ChatNote")
class ChatNoteCommands(Cog, name="ChatNote"):
@commands.command(
help="Adds a new note to your current notebook, or the specified notebook",
brief="Adds a note to a notebook",
pass_context=True
)
async def note(self, ctx, *, text):
note_text = text.strip()
await ctx.channel.send("Noted: " + note_text)
@commands.command(pass_context=True)
async def help(self, ctx, *args):
return await commands.bot._default_help_command(ctx, *args)
bot.remove_command("help")
bot.add_cog(ChatNoteCommands())
bot.run(DISCORD_TOKEN)
但是这段代码给了我错误:
Command raised an exception: AttributeError: module 'discord.ext.commands.bot' has no attribute '_default_help_command'
如果我将 _default_help_command 换成自动完成提供给我的方法 DefaultHelpCommand,我会收到一个新错误:
Command raised an exception: TypeError: can't pickle _asyncio.Future objects
错误的含义很明显,但我应该使用什么方法名,或者,一般来说,我的代码有什么问题?
【问题讨论】:
-
您是否正在尝试获取命令帮助,例如命令
##help note以使机器人回复“note”命令描述?还是您想返回显示所有命令的默认帮助菜单? -
@LoremI。我正在尝试显示所有命令的默认帮助菜单,但
help与note在同一类别中,而不是在它自己的No Category中
标签: python python-3.x discord bots discord.py