Reputation: 327
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
Upvotes: 6
Views: 14351
Reputation: 21
@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
Upvotes: 2
Reputation: 1
@bot.command()
async def commandcount(ctx):
counter = 0
for command in bot.commands:
counter += 1
await ctx.send(f"There are `{counter}` commands!")
Upvotes: -1
Reputation: 1079
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)
Upvotes: 8
Reputation: 61014
Those are the Command
objects that your bot has. The reason there are two is because your bot has a built-in help
command that does exactly what you're looking for. If your clear
command was
@bot.command()
async def clear(ctx):
"A command for clearing stuff"
pass
then running !help
would give you the output
No Category: help Shows this message. clear A command for clearing stuff Type !help command for more info on a command. You can also type !help category for more info on a category.
Upvotes: 0