Skip to content Skip to sidebar Skip to footer

List The Commands In A Discord.py Cog

With discord.py, you can list the commands of a bot. This is best exemplified here: x = [] for y in client.commands: x.append(y.name) print(x) How would one do this with a spe

Solution 1:

You can check which cog the command belongs with Command.cog. Note that this will be None if the command does not belong to a cog.

cog.py

from discord.ext import commands

classTest(commands.Cog):
    def__init__(self, bot):
        self.bot = bot

    @commands.command()asyncdeffoo(self, ctx):
        await ctx.send('bar')

defsetup(bot):
    bot.add_cog(Test(bot))

bot.py

from discord.ext import commands

client=commands.Bot(command_prefix='!')

client.load_extension('cog')

@client.command()asyncdefping(ctx):
    await ctx.send('pong')

x = []
for y in client.commands:
    if y.cog and y.cog.qualified_name == 'Test':
        x.append(y.name)
print(x)

client.run('token')

Post a Comment for "List The Commands In A Discord.py Cog"