I am current trying to make a Discord bot that joins VC when a certain person joins and then leaves VC when they leave.
The bot should ONLY be in VC when the specific user is in VC, and then leave instantly when said user disconnects.
The problem I am having is trying to figure out how to make the bot detect the user leaving and leave.
@bot.event
async def on_voice_state_update(member, before, after):
targetID = bot.get_user(USERID)
if after.channel is not None and member.id == targetID.id:
await member.voice.channel.connect()
This is what I use to make the bot join the VC and there seem to be no issues, but no matter what I try I cannot figure out how to make the bot leave once the said user leaves VC.
Any help is appreciated, thank you.
Any time i've been able to make the bot leave, it leaves the instant is joins, I know the reason for this but I just cant figure out how to prevent it, or do it another way to make the bot only leave when the user leaves.
targetID.id
not return an error for you? What aboutbot.get_user(USERID)
? For me they returned errors. What version of Python are you on, and what version of Discord.py are you using (if you know)?