I want when a user is joining this temp channel to rename the channel as his Name#0000 - Discord_ID
and when leaving from this temp vc to get deleted. How it can be done?
client.on('voiceStateUpdate', (oldState, newState) => {
if (newState.channelID === 'channelID') { // You can also use `newState.channelID`
newState.guild.channels.create("Tester", {
type: 'voice',
parent: 'categoryID'
}).then(vc => {
newState.setChannel(vc);
})
}
});
CodePudding user response:
heres the code to make it name the channel with the member name, and delete it after leaving, i edited your code a bit
client.on('voiceStateUpdate', (oldState, newState) => {
if (newState.channel?.name === 'Replace with channel name') { // You can also use `newState.channelID`
newState.guild.channels.create(`${newState.member.user.username}#${newState.member.user.discriminator}`, {
type: 'GUILD_VOICE',
parent: 'Replace with category id',
}).then(vc => {
newState.setChannel(vc);
})
}
if (oldState.channel?.name === `${oldState.member.user.username}#${oldState.member.user.discriminator}`) {
oldState.channel?.delete()
}
});
Just make sure to put the channel name, and the category id!
Also, those "?" in the codes are for typescript, if you're using JavaScript, then you won't need them.