Python 不和谐机器人加入/离开

Python 不和谐机器人加入/离开,python,discord,bots,Python,Discord,Bots,我正在为我的机器人使用此代码。bot可以加入但不能离开,它会在发送命令时忽略要离开的命令。这应该可以工作: @Bot.command() async def leave( ctx): if (ctx.voice_client): await ctx.guild.voice_client.disconnect() await ctx.send('Bot left') else: await ctx.send(&qu

我正在为我的机器人使用此代码。bot可以加入但不能离开,它会在发送命令时忽略要离开的命令。

这应该可以工作:

@Bot.command()

async def leave(

        ctx):
    if (ctx.voice_client):
        await ctx.guild.voice_client.disconnect()
        await ctx.send('Bot left')
    else:
        await ctx.send("I'm not in a voice channel, use the join command to make me join")
@Bot.command()

async def leave(

        ctx):
    if (ctx.voice_client):
        await ctx.guild.voice_client.disconnect()
        await ctx.send('Bot left')
    else:
        await ctx.send("I'm not in a voice channel, use the join command to make me join")
@Bot.command(description="joins a voice channel")
    async def join(ctx):
        if ctx.author.voice is None or ctx.author.voice.channel is None:
            return await ctx.send('You need to be in a voice channel to use this command!')

        voice_channel = ctx.author.voice.channel
        if ctx.voice_client is None:
            vc = await voice_channel.connect()
        else:
            await ctx.voice_client.move_to(voice_channel)
            vc = ctx.voice_client

@Bot.command(description="stops and disconnects the bot from voice")
    async def leave(ctx):
        if ctx.voice_client is None:
            await ctx.send("I'm not in a voice channel, use the join command to make me join")
        else:
            await ctx.voice_client.disconnect()
            await ctx.send('Bot left')