我试图在重写时获取我的 Discord 机器人中所有命令的列表。我正在使用 Python 3.6 来编写这个我试图通过这样做来打印命令列表 print(bot.commands) 这只为我提供了以下返回:{<discord.ext.commands.core.Command object at 0x00000209EE6AD4E0>, <discord.ext.commands.core.Command object at 0x00000209EE6AD470>}我希望通常的输出是clear(),因为这是迄今为止我在机器人中编程的唯一命令,该命令按预期工作。但它只打印上面的
3 回答

蛊毒传说
TA贡献1895条经验 获得超3个赞
我想你正在寻找这样的东西。
@bot.command(name="help", description="Returns all commands available")
async def help(ctx):
helptext = "```"
for command in self.bot.commands:
helptext+=f"{command}\n"
helptext+="```"
await ctx.send(helptext)

呼唤远方
TA贡献1856条经验 获得超11个赞
这些是Command您的机器人拥有的对象。有两个原因是因为您的机器人有一个内置help命令,可以完全满足您的要求。如果你的clear命令是
@bot.command()
async def clear(ctx):
"A command for clearing stuff"
pass
然后运行!help会给你输出
无类别:
帮助 显示此消息。
clear 清除东西的命令
键入 !help command 以获取有关命令的更多信息。
您还可以键入 !help category 以获取有关类别的更多信息。
添加回答
举报
0/150
提交
取消