我有一个Discord机器人,我试图将默认help命令的帮助与其他命令的帮助归为同一类。当我什么都不做时,默认的帮助命令显示:
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
这种错误的含义很明显,但是我应该使用什么方法名称,或者总的来说,我的代码有什么问题?
答案 0 :(得分:0)
您可以使用bot.help_command.cog
来设置help_command的cog
。
from discord.ext import commands
bot = commands.Bot(command_prefix="##", case_insensitive=True, name="ChatNote")
class ChatNoteCommands(commands.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)
bot.add_cog(ChatNoteCommands())
bot.help_command.cog = bot.cogs["ChatNote"]
bot.run(TOKEN)