Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.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
Discord.py discord 1.0.1的小问题让机器人离开_Discord.py - Fatal编程技术网

Discord.py discord 1.0.1的小问题让机器人离开

Discord.py discord 1.0.1的小问题让机器人离开,discord.py,Discord.py,现在我有这个 @client.command() async def comrade(ctx, amountt=30): if not ctx.message.author.voice: await ctx.send("You are not connected to a voice channel") return else: channel = ctx.message.author.voice.ch

现在我有这个

@client.command()
async def comrade(ctx, amountt=30):
    if not ctx.message.author.voice:
        await ctx.send("You are not connected to a voice channel")
        return
    
    else:
        channel = ctx.message.author.voice.channel

    vc = await channel.connect()
    vc.play(discord.FFmpegPCMAudio('songs.mp3'))
但如果机器人已经连接到语音频道,我想不出如何让它离开

我也试过这个,但不起作用:

def is_connected(ctx):
    voice_client = get(ctx.bot.voice_clients, guild=ctx.guild)
    return voice_client and voice_client.is_connected()

我看不出您的代码中有任何错误,但离开频道的最简单方法是下一个:

异步def离开(ctx):
voice=ctx.voice_client#每个公会只能有一个vc客户端,这就是为什么这是有效的
如果语音为“无”:
#机器人不在语音频道中
return wait ctx.send(“机器人不在语音通道中”)
#离开英吉利海峡
等待语音。断开连接()
参考:

等等,你真的在使用discord.py吗?不,标签是discord.py我在使用discord.py 1.5.1,discord库它是1.0.1