I'm trying to make a discord bot that gives a user role when they join a voice channel and removes the role when they leave it. I know about on_voice_state_update and how to give a user a role but I don't know how to get what user joined the channel to give them the role.
Right now my code is slightly modified version of the answer from How to use discord.py event handler on_voice_state_update to run only when a user joins a voice channel.
@client.event
async def on_voice_state_update(before, after ):
if before.voice.voice_channel is None and after.voice.voice_channel is not None:
for channel in before.server.channels:
if channel.name == 'general':
await client.send_message(channel, "User joined")
elif before.voice.voice_channel is not None and after.voice.voice_channel is None:
for channel in before.server.channels:
if channel.name == 'general':
await client.send_message(channel, "User left");