下面是将机器人与vc断开连接的代码。但是它显示了这个错误AttributeError:'Interaction‘对象没有属性'voice_client’--我查看了https://discordpy.readthedocs.io/
并尝试手动添加它,但是它不起作用。
@bot.tree.command(name="disconnect", description="Disconnect from a vc",guild=guild)
async def disconnect(ctx: commands.Context):
if not ctx.client:
return await ctx.send("I am not in vc")
elif not ctx.user.voice:
return await ctx.send("You are not in vc")
else:
vc: wavelink.Player = ctx.client
await vc.disconnect()
vc.queue.clear()
await ctx.send("Bye-bye")
发布于 2022-09-18 06:21:52
我找到了答案,创建了guild = Interaction.guild
,然后使用这个guild.voice_client
发布于 2022-09-14 15:27:03
给定函数中的bot.tree.command
装饰器的第一个参数不是commands.Context
,而是discord.Interaction
,因为您的错误告诉您
https://stackoverflow.com/questions/73721387
复制