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

2024-09-30 16:36:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在重写中列出我的Discord bot中的所有命令。我使用python3.6编写这个

我试图通过 print(bot.commands) 这只为我提供了以下回报:

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

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


Tags: core命令内容objectbot编程extcommand
2条回答

这些是bot拥有的Command对象。之所以有两个,是因为您的bot有一个内置的help命令,它完全符合您的需要。如果您的clear命令是

@bot.command()
async def clear(ctx):
    "A command for clearing stuff"
    pass

然后运行!help将得到输出

^{pr2}$

我想你在找这样的东西。在

@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)

相关问题 更多 >