How can I move a user to a specific voice channel?
Question:
I’m trying to create a system using Python that when a user joins a Discord VC by a specific ID, it moves them to a specific output/destination voice channel.
I was wondering how to do this correctly. If possible, use pairs to have multiple Source to Destination IDs using pairs or arrays.
Answers:
This is possible, by using the on_voice_state_update
event, which offers the discord.py library.
First, you check if the user joined the voice
channel and after that, you get the destination voice
channel object and move the user to it.
Don’t forget to replace DESTINATION_CHANNEL_ID
and SOURCE_CHANNEL_ID
.
@client.event
async def on_voice_state_update(member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
# check if the user joined a voice channel
if before.channel is None and after.channel is not None:
# if you want to include multiple sources and destinations, you should check for the channel_id.
if after.channel.id = SOURCE_CHANNEL_ID:
destination_voice = member.guild.get_channel(DESTINATION_CHANNEL_ID)
# Move the user to the destination voice channel.
await member.move_to(destination_voice, reason="Moved by bot")
# check for other channel
elif after.channel.id = SOURCE_CHANNEL_ID2:
destination_voice = member.guild.get_channel(DESTINATION_CHANNEL_ID2)
# Move the user to the destination voice channel.
await member.move_to(destination_voice, reason="Moved by bot")
I’m trying to create a system using Python that when a user joins a Discord VC by a specific ID, it moves them to a specific output/destination voice channel.
I was wondering how to do this correctly. If possible, use pairs to have multiple Source to Destination IDs using pairs or arrays.
This is possible, by using the on_voice_state_update
event, which offers the discord.py library.
First, you check if the user joined the voice
channel and after that, you get the destination voice
channel object and move the user to it.
Don’t forget to replace DESTINATION_CHANNEL_ID
and SOURCE_CHANNEL_ID
.
@client.event
async def on_voice_state_update(member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
# check if the user joined a voice channel
if before.channel is None and after.channel is not None:
# if you want to include multiple sources and destinations, you should check for the channel_id.
if after.channel.id = SOURCE_CHANNEL_ID:
destination_voice = member.guild.get_channel(DESTINATION_CHANNEL_ID)
# Move the user to the destination voice channel.
await member.move_to(destination_voice, reason="Moved by bot")
# check for other channel
elif after.channel.id = SOURCE_CHANNEL_ID2:
destination_voice = member.guild.get_channel(DESTINATION_CHANNEL_ID2)
# Move the user to the destination voice channel.
await member.move_to(destination_voice, reason="Moved by bot")