'How can I create a listener for creating voice channels with discord.js?
I have been trying to create sort of a listener thing, where if a person joins a voice channel called "Join to Create", it creates another voice channel named "voice - " in a specific category, and then it moves them in the newly created voice channel, and I want the newly created channel to have a max of 3 members allowed to join, also once everyone has left the channel and the channel is completely empty it deletes it.
Thanks to anyone that helps in advance.
Solution 1:[1]
Let's create a voice channel with user limit
let FinalChannel; //Put this outside functions so that we can use it later
message.guild.channels.create('Voics-!!!', "voice").then(c => {
c.setUserLimit("5");
FinalChannel = c;
});
Then,
client.on('voiceStateUpdate', (oldState, newState) => {
if (oldState.member.user.bot) return; //Bot filter
if(!newState.channelID) return; //left Channel
if(newState.channelID !== "Join Voice Channel ID") return; //We don't care about other channels
if(FinalChannel.members.cache.size < FinalChannel.userLimit){ //Check if there's more user than limit
newState.member.setChannel(FinalChannel);
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Akio |
