Skip to content Skip to sidebar Skip to footer

How To Make A Bot That Gives Role When We Join A Particular Voice Channel And Removes When Left

I am learning how to use discord.py and I want to make bot feature that give role when we join particular voice channel and removes the same role when user leaves the channel @clie

Solution 1:

on_voice_state_update gives you after and before arguments, here's how to check when a member joined and left a voice channel

asyncdefon_voice_state_update(member, before, after):
    if before.channel isNoneand after.channel isnotNone:
        # member joined a voice channel, add the roles hereelif before.channel isnotNoneand after.channel isNone:
        # member left a voice channel, remove the roles here

To add roles, first you need to get a discord.Role object, then you can do member.add_roles(role)

role = member.guild.get_role(role_id)

await member.add_roles(role)

To remove a role is the same, but .remove_roles

await member.remove_roles(role)

EDIT:

asyncdefon_voice_state_update(member, before, after):
    channel = before.channel or after.channel

    if channel.id == some_id:
        if before.channel isNoneand after.channel isnotNone:
            # member joined a voice channel, add the roles hereelif before.channel isnotNoneand after.channel  isNone:
            # member left a voice channel, remove the roles here

Reference:

Post a Comment for "How To Make A Bot That Gives Role When We Join A Particular Voice Channel And Removes When Left"