Python 我试图制作一个简单的不和谐机器人,加入并离开一个语音频道,但我不能让机器人离开这个频道
第一个命令起作用,机器人加入我所在的语音频道。但每当我尝试使用第二个命令时,就会出现错误: discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“VoiceChannel”对象没有属性“disconnect” 提前谢谢你的帮助 像这样离开vcPython 我试图制作一个简单的不和谐机器人,加入并离开一个语音频道,但我不能让机器人离开这个频道,python,discord.py,Python,Discord.py,第一个命令起作用,机器人加入我所在的语音频道。但每当我尝试使用第二个命令时,就会出现错误: discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“VoiceChannel”对象没有属性“disconnect” 提前谢谢你的帮助 像这样离开vc # this command makes the bot join the voice channel @bot.command() async def join(ctx
# 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()
建议-检查机器人是否在vc中,否则可能发生错误
@bot.command()
async def leave(ctx): # If the bot is in a voice channel
await ctx.guild.voice_client.disconnect()
你可能不想看一眼。
if ctx.voice_client == True:pass