首页 > 解决方案 > Discord.py bot 不会加入 vc

问题描述

我试图让我的 discord.py 机器人加入我所在的 vc。但是当我运行命令时,机器人不想加入 vc。我该如何解决这个问题?谢谢。代码如下。

@bot.command()
async def join(ctx):
  channel = ctx.message.author.voice.voice_channel
  await bot.join_voice_channel(channel)

标签: pythondiscorddiscord.py

解决方案


根据discord.Member.voice(where you did ctx.message.author.voice...) 的文档,voice_channel这不是一个有效的属性。channel而是一个有效的属性。

此外,您不必这样做ctx.message.author,而是使用ctx.author. 快多了。

所以,你的变量channel可以这样定义,你应该像这样连接到通道:

channel = ctx.author.voice.channel
await channel.connect()

这应该有效。


推荐阅读