如何在 pycord 中同步来自 cogs 的斜杠命令?

问题描述 投票:0回答:1

我尝试与 ctx.bot.tree.sync() 同步,但总是收到“Bot”对象没有属性“tree”的错误

Main.py(同步命令)

@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")
discord.py slash pycord
1个回答
0
投票

我也遇到了同样的问题,建议使用交互来代替

@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) 

确保您已正确定义机器人

© www.soinside.com 2019 - 2024. All rights reserved.