import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!') # 设置 bot 前缀为 !
@bot.command()
async def count(ctx):
"""显示已使用的应用命令数量"""
app_info = await bot.application_info()
count = len(app_info.commands)
await ctx.send(f"已使用的应用命令数量为 {count}")
bot.run('BOT_TOKEN') # 用你的 bot token 替换此处的 BOT_TOKEN
在这里,我们定义了一个 count
命令,当用户输入 !count
时会触发该命令。在命令方法中,我们通过使用 bot.application_info()
获取 bot 应用信息,然后通过 len(app_info.commands)
计算已使用的应用命令数量,并将其发送回用户。请确保将 BOT_TOKEN
替换为你的 bot token。