The question is published on by Tutorial Guruji team.
I have a command which creates a voice channel with certain permissions and puts it under a category. Instead, I want the voice channel to be created when you join a specific voice channel called “Join to create” and you are moved to the new voice channel after it is created. I also want the new voice channel to automatically delete once everyone has left it.
I’m not quite sure how to do this so I’d really appreciate the help. Here is the code for the command:
if (command === "createvc") { message.guild.channels.create(message.author.username + "'s Channel", { type: 'voice', parent: '703315964011479090', permissionOverwrites: [ { id: message.guild.id, // everyone allow: ['CREATE_INSTANT_INVITE', 'VIEW_CHANNEL', 'CONNECT', 'SPEAK', 'STREAM', 'USE_VAD'], deny: ['MANAGE_CHANNELS', 'MANAGE_ROLES', 'MANAGE_WEBHOOKS', 'MUTE_MEMBERS', 'DEAFEN_MEMBERS', 'MOVE_MEMBERS', 'PRIORITY_SPEAKER'] }, { id: '705036984934203473', // Muted allow: ['CREATE_INSTANT_INVITE', 'VIEW_CHANNEL'], deny: ['CONNECT', 'SPEAK', 'STREAM', 'USE_VAD', 'MANAGE_CHANNELS', 'MANAGE_ROLES', 'MANAGE_WEBHOOKS', 'MUTE_MEMBERS', 'DEAFEN_MEMBERS', 'MOVE_MEMBERS', 'PRIORITY_SPEAKER'] }, { id: '705036553872998470', // Unverified deny: ['CREATE_INSTANT_INVITE', 'VIEW_CHANNEL', 'CONNECT', 'SPEAK', 'STREAM', 'USE_VAD', 'MANAGE_CHANNELS', 'MANAGE_ROLES', 'MANAGE_WEBHOOKS', 'MUTE_MEMBERS', 'DEAFEN_MEMBERS', 'MOVE_MEMBERS', 'PRIORITY_SPEAKER'] }, ], }) }
Thank you in advance.
Answer
You can detect if someone joined the Join to Create
channel using the voiceStateUpdate
event and then creating a new voice channel using guild.channels.create()
and then finally by moving the GuildMember
(s) to that voice channel.
Your solution would be something like this:
client.on('voiceStateUpdate', (oldState, newState) => { if (newState.channel.name === 'Join to Create') { // You can also use `newState.channelID` newState.guild.channels.create("New Channel", { type: 'voice', parent: 'CATEGORY_ID' }).then(vc => { newState.setChannel(vc); }) } });