Get all bot commands discord.py
Question:
I’m making a help command using discord.py rewrite and I need a way to iterate over all the commands I already have inside the bot, is there a way to do like bot.get_all_commands?
for command in bot.get_all_commands:
print(command)
Answers:
bot.commands
returns all commands as command objects in a set.
You can use bot.all_commands
to return all commands & aliases that you used before, See more in discord.ext.command .
This worked for me
commands = bot.get_my_commands()
for command in commands:
print(command)
With version 2.0.0 and above, to get all commands we also need to get the new app command as well. Use the bot.walk_commands()
method instead of bot.commands
to get those under a group.
I’ve done it with this function:
def get_all_commands(bot):
return [
*bot.walk_commands(),
*bot.tree.walk_commands()
]
I’m making a help command using discord.py rewrite and I need a way to iterate over all the commands I already have inside the bot, is there a way to do like bot.get_all_commands?
for command in bot.get_all_commands:
print(command)
bot.commands
returns all commands as command objects in a set.
You can use bot.all_commands
to return all commands & aliases that you used before, See more in discord.ext.command .
This worked for me
commands = bot.get_my_commands()
for command in commands:
print(command)
With version 2.0.0 and above, to get all commands we also need to get the new app command as well. Use the bot.walk_commands()
method instead of bot.commands
to get those under a group.
I’ve done it with this function:
def get_all_commands(bot):
return [
*bot.walk_commands(),
*bot.tree.walk_commands()
]