Discord.py 重写所有命令的收集列表

我试图在重写时获取我的 Discord 机器人中所有命令的列表。我正在使用 Python 3.6 来编写这个


我试图通过这样做来打印命令列表 print(bot.commands) 这只为我提供了以下返回:


{<discord.ext.commands.core.Command object at 0x00000209EE6AD4E0>, <discord.ext.commands.core.Command object at 0x00000209EE6AD470>}


我希望通常的输出是clear(),因为这是迄今为止我在机器人中编程的唯一命令,该命令按预期工作。但它只打印上面的


暮色呼如
浏览 194回答 3
3回答

蛊毒传说

我想你正在寻找这样的东西。@bot.command(name="help", description="Returns all commands available")async def help(ctx):&nbsp; &nbsp; helptext = "```"&nbsp; &nbsp; for command in self.bot.commands:&nbsp; &nbsp; &nbsp; &nbsp; helptext+=f"{command}\n"&nbsp; &nbsp; helptext+="```"&nbsp; &nbsp; await ctx.send(helptext)

呼唤远方

这些是Command您的机器人拥有的对象。有两个原因是因为您的机器人有一个内置help命令,可以完全满足您的要求。如果你的clear命令是@bot.command()async def clear(ctx):&nbsp; &nbsp; "A command for clearing stuff"&nbsp; &nbsp; pass然后运行!help会给你输出&nbsp;无类别:&nbsp; 帮助 显示此消息。&nbsp; clear 清除东西的命令键入 !help command 以获取有关命令的更多信息。您还可以键入 !help category 以获取有关类别的更多信息。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python