Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我试图制作一个简单的不和谐机器人,加入并离开一个语音频道,但我不能让机器人离开这个频道_Python_Discord.py - Fatal编程技术网

Python 我试图制作一个简单的不和谐机器人,加入并离开一个语音频道,但我不能让机器人离开这个频道

Python 我试图制作一个简单的不和谐机器人,加入并离开一个语音频道,但我不能让机器人离开这个频道,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

第一个命令起作用,机器人加入我所在的语音频道。但每当我尝试使用第二个命令时,就会出现错误: discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“VoiceChannel”对象没有属性“disconnect”

提前谢谢你的帮助

像这样离开vc

# 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