Leaving voice channel in discord.py isn't working

31 Views Asked by At

I've tried for quite a while now but can't get my code to work:

import discord
from discord.ext import commands
from asyncio import sleep

intents = discord.Intents().all()
client = commands.Bot(command_prefix="$", intents=intents)


@client.event
async def on_ready():
    print("Online!! :3")
    await client.change_presence(
        activity=discord.Activity(
            type=discord.ActivityType.watching, name="humanity fail."
        )
    )


async def on_member_join(member):
    role = discord.utils.get(member.guild.roles, name="sus")
    await member.add_roles(role)

@client.event
async def on_voice_state_update(member, before, after):
    if not member.bot:
        if after.channel and not before.channel:
            voice_client = await after.channel.connect()
            await sleep(1)
            await voice_client.disconnect()

client.run(token_here) # The token was there, dw

It doesn't give an error or anything, the bot just won't leave the vc.

I tried changing the code and using multiple methods, nothing is working.

0

There are 0 best solutions below