我们可以使用 Pycord 中的 Bot 对象中的 commands 属性来获取已加载的所有命令,并通过对其长度进行计数来获取使用的应用程序命令数量。然后,我们可以将其作为字符串发送给 Discord。
下面是示例代码:
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.command()
async def command_count(ctx):
num_commands = len(bot.commands)
await ctx.send(f"当前使用的应用程序命令数量为: {num_commands}")
bot.run('your-token-here')
在上面的示例中,我们创建了一个名为 command_count 的命令,该命令通过获取 bot.commands 中的命令数量并使用字符串插值将其发送给 Discord。
要使用此命令,请在 Discord 中键入“!command_count”即可。