我尝试与 ctx.bot.tree.sync() 同步,但总是收到“Bot”对象没有属性“tree”的错误
@bot.slash_command(name="sync")
async def sync(ctx):
await ctx.defer(ephemeral=True)
cmds = await ctx.bot.tree.sync()
await ctx.send(f"succesfully synced {len(cmds)} commands global")
我也遇到了同样的问题,建议使用交互来代替
@bot.hybrid_command(name="sync")
async def sync(interaction:discord.Interaction):
try:
cmds = await bot.tree.sync()
await interaction.reply(f"succesfully synced {len(cmds)} global commands")
except Exception as e:
await interaction.reply(f"Error Syncing Commands: {e}",ephemeral=True)
确保您已正确定义机器人