Reputation: 46
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 specific cog?
Upvotes: 1
Views: 1563
Reputation: 3497
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
class Test(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def foo(self, ctx):
await ctx.send('bar')
def setup(bot):
bot.add_cog(Test(bot))
bot.py
from discord.ext import commands
client=commands.Bot(command_prefix='!')
client.load_extension('cog')
@client.command()
async def ping(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')
Upvotes: 2