Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.py Rewrite gathering list of all commands

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

like image 1000
Generic Nerd Avatar asked Dec 24 '18 11:12

Generic Nerd


2 Answers

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)
like image 117
damaredayo Avatar answered Sep 30 '22 18:09

damaredayo


@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

like image 38
Karnav Thakur Avatar answered Sep 30 '22 18:09

Karnav Thakur