# this command makes the bot join the voice channel
@bot.command()
async def join(ctx):
voice_channel = ctx.author.voice.channel
await voice_channel.connect()
# this was my attempt to make it leave that does not work
@bot.command()
async def leave(ctx):
voice_channel = ctx.author.voice.channel
await voice_channel.disconnect()
第一个命令有效,机器人加入我所在的语音通道。但是每当我尝试使用第二个命令时,我都会收到错误消息: discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'VoiceChannel'对象没有'disconnect'属性
提前感谢您的帮助!
答案 0 :(得分:0)
就这样离开vc
@bot.command()
async def leave(ctx): # If the bot is in a voice channel
await ctx.guild.voice_client.disconnect()
建议 - 检查 bot 是否在 vc 中或可能发生错误
if ctx.voice_client == True:pass