I’m making a bot that will perform one function, when a user enters a specific channel with a specified ID, a new channel is created and transferred there, but the code does not work, here is my code:
const { Client } = require('discord.js');
const client = new Client({
intents: [
1 << 0, // GUILDS
1 << 3 // GUILD_VOICE_STATES
]
});
client.once('ready', () => {
console.log('Бот готов!');
});
client.on('joinVoiceChannel', async (member, channel) => {
const voiceChannelID = '1237383248955445302';
if (channel.id === voiceChannelID) {
console.log('User joined the specified voice channel');
const guild = member.guild;
try {
const newChannel = await guild.channels.create(`channel-${member.user.username}`, {
type: 'GUILD_VOICE',
parent: channel.parent,
});
await member.voice.setChannel(newChannel);
console.log(`User moved to the new channel: ${newChannel.name}`);
newChannel.client.on('voiceStateUpdate', (oldState) => {
if (oldState.channel.members.size === 0) {
oldState.channel.delete()
.then(console.log(`Channel ${oldState.channel.name} deleted because it's empty`))
.catch(console.error);
}
});
} catch (error) {
console.error(`Error creating/moving user to the new channel: ${error}`);
}
}
});
client.login('TOKEN');
Help me please))))))))
New contributor
FingerPrint171717 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.