Answer the question
In order to leave comments, you need to log in
How to make the bot remove the role of a participant in a certain voice channel?
I wrote a bot in the discord, I want to make it shoot the role of the participant in a certain voice channel.
Wrote like this:
@client.event
async def on_voice_state_update(member, before, after):
role1 = discord.utils.get(member.guild.roles, id = 804852310966140978)
if before.channel and not after.channel:
if before.channel.id == 804901448931475506:
await member.remove_roles(role1)
Answer the question
In order to leave comments, you need to log in
Your condition is written
IF before.channel exists AND after.channel does NOT exist.
It turns out that this condition will work only when the user does not go to another channel, but exits the voice channel altogether, so the role is not removed when switching to another channel.
It would be more correct to check only the presence of before.channel and compare its id with the desired one, and if it matches, then remove the role, and you don’t care where the user left.
Those.
@client.event
async def on_voice_state_update(member, before, after):
role1 = discord.utils.get(member.guild.roles, id = 804852310966140978)
if before.channel:
if before.channel.id == 804901448931475506:
await member.remove_roles(role1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question