commands.Bot与interactions.Client对比:Discord Bot开发该如何选择?
Discord机器人徽章领取与命令选型问题解决
问题核心
你领不到Active Developer徽章的原因很明确:Discord的要求是本月内机器人有至少1条slash命令被执行,前缀命令不算入统计范围。
选型与迁移方案
1. 继续用commands.Bot(discord.py)
完全没必要转interactions库,discord.py本身就支持slash命令(应用命令),直接加命令schema就行:
- 添加slash命令示例:
from discord import app_commands from discord.ext import commands bot = commands.Bot(command_prefix="!", intents=...) # 注册slash命令 @bot.tree.command(name="test", description="测试用slash命令") async def test_slash(interaction): await interaction.response.send_message("这条命令会被徽章系统统计到!") # 同步命令到Discord(全局同步可能等1小时,指定服务器能快速生效) @bot.event async def on_ready(): # 全局同步 await bot.tree.sync() # 或者指定服务器:await bot.tree.sync(guild=discord.Object(id=你的服务器ID)) print(f"机器人已登录:{bot.user}") - 迁移现有前缀命令:
可以给原有逻辑套上slash命令的装饰器,同时保留前缀命令,比如:# 原前缀命令 @commands.command() async def hello(ctx): await ctx.send("前缀命令:你好!") # 对应的slash命令 @app_commands.command(name="hello", description="打招呼的slash命令") async def hello_slash(interaction): await interaction.response.send_message("Slash命令:你好!")
2. 转用interactions库
如果你的机器人功能还简单,转用也可以,但属于没必要的折腾——discord.py的应用命令功能已经完全满足需求,而且生态更成熟、文档更全。interactions库只是更专注于slash命令开发而已。
徽章领取必做步骤
- 确保slash命令已经同步到Discord
- 用自己的账号在本月内执行一次该命令
- 等几个小时让Discord统计数据更新,再去尝试领取徽章
内容的提问来源于stack exchange,提问作者Andrew
相关产品推荐
相关产品推荐

