在discord.py齿轮中列出命令 [英] List the Commands in a discord.py Cog
本文介绍了在discord.py齿轮中列出命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用discord.py,您可以列出机器人的命令.这是最好的例证:
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?
推荐答案
您可以通过 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')
这篇关于在discord.py齿轮中列出命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文