【发布时间】:2021-06-29 04:00:21
【问题描述】:
使用 discord.py,您可以列出机器人的命令。这是最好的例证:
x = []
for y in client.commands:
x.append(y.name)
print(x)
如何使用特定的 cog 做到这一点?
【问题讨论】:
标签: python python-3.x discord discord.py
使用 discord.py,您可以列出机器人的命令。这是最好的例证:
x = []
for y in client.commands:
x.append(y.name)
print(x)
如何使用特定的 cog 做到这一点?
【问题讨论】:
标签: python python-3.x discord discord.py
您可以使用Command.cog 检查该命令属于哪个齿轮。请注意,如果该命令不属于某个 cog,则这将是 None。
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')
【讨论】:
qualified_name