我知道我是新来的,但我有一个问题要问你:
如果您想用Python编写带有特殊嵌齿轮的Discord机器人,并将其替换为默认的help命令,该怎么办:
@commands.command(pass_context=True)
async def help(self,ctx,*cog:str):
"""Gives you info on my cogs *and* their commands."""
if not cog:
halp=discord.Embed(title='Cog Listing and Uncatergorized Commands',
description='Use `!help *cog*` to find out more about them!')
cogs_desc = ''
for x in self.bot.cogs:
cogs_desc += ('{} - {}'.format(x,self.bot.cogs[x].__doc__)+'\n')
halp.add_field(name='Cogs',value=cogs_desc[0:len(cogs_desc)-1])
else:
halp=discord.Embed(title='{cog} Command Listing')
for x in self.bot.cogs[cog]:
halp.add_field(name=x,value=x.__doc__)
await self.bot.whisper(embed=halp)
...并且该命令可以将有关机器人的齿轮的信息发送得很好,但是拒绝为您提供有关特定齿轮的命令的信息,并且可以为您提供此信息:
Ignoring exception in command help
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 50, in wrapped
ret = yield from coro(*args, **kwargs)
File "/home/pi/Documents/Coding/Python/AwesomeDiscordBot/cogs/info.py", line 49, in help
for x in self.bot.cogs[cog]:
KeyError: ('Info',)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/discord/ext/commands/bot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "/home/pi/.local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 374, in invoke
yield from injected(*ctx.args, **ctx.kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 54, in wrapped
raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: ('Info',)
您将如何修复它,以便可以使用Discord机器人的!help命令来获取有关齿轮和其命令的信息?
P.S。我在Raspberry Pi上使用Python 3.5,并且我希望在嵌入的主要帮助中也包含未分类的命令。