I'm using discord.js v13.
I want to disconnect all members from a voice channel. Using interaction.guild.channels.fetch(), I'm able to get voice channels and the members' information.
But when I switch the voice channel, the data is still wrong because it's not updating.
This is my code:
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
switch (commandName) {
case 'channels':
const channelInput = interaction.options.getString('channelname');
const channelExist = (await interaction.guild.channels.fetch()).find(channel => {
return channel.name == channelInput && channel.isVoice()
})
if (!channelExist) {
await interaction.reply('no voice channel');
break;
}
console.log(channelExist.members)
console.log('===========')
break;
}
});
How can I fix this problem?
To receive updates from voice channels on who is joining and leaving which channels you need to supply you client with the GUILD_VOICE_STATES intent. That will allow your data to update.