1
votes

I am learning discord.py and I want to make bot that sends embedded message like.(@user has joined!) joined in particular text channel only eg.(#music-cnsole) when users join particular voice channel eg.(music.vc)

  • like this enter image description here

when user joins

  • also enter image description here

when user leaves

@client.event
async def on_voice_state_update(member, before, after):
1

1 Answers

2
votes
channelId = 1234567891011 # Your text channel id here
voiceChannelId = 1234567891011 # Your voice channel id here

@bot.event
async def on_voice_state_update(member, before, after):
    if ((before.channel != None and before.channel.id == voiceChannelId) or (after.channel != None and after.channel.id == voiceChannelId)): # if connected/disconected to voiceChannelId channel
        channel = bot.get_channel(channelId) # gets channel object
        if (before.channel == None and after.channel != None): # if user connect
            channel.send(f"{member.mention} connected to voice {after.channel.name}") # send message to channel
        elif (before.channel != None and after.channel == None): # if user disconnect
            channel.send(f"{member.mention} disconnect from voice {before.channel.name}") # send message to channel

on_voice_state_update event in docs

Pardon for many edits.