I'm trying to get a list of all the commands within my Discord bot in rewrite. I am using Python 3.6 to write this
I have tried to print a list of the commands by doing
print(bot.commands)
This only provided me with the following return:
{<discord.ext.commands.core.Command object at 0x00000209EE6AD4E0>, <discord.ext.commands.core.Command object at 0x00000209EE6AD470>}
I expect the usual output to be clear()
, as that is the only command that I have programmed within the bot so far, the command works as expected. But it only prints the above
I think you're looking for something like this.
@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)
@commands.command(help = "Blah")
async def l1(self,ctx):
commands = [c.name for c in self.client.commands]
print(commands)
What you are getting is the command object, so if you want the name of the command you can get the name as Command.name
.
Reference : https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Command.name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With