I'm trying to get all users inside voice channel in my server. When someone talks to bot in #general, I want to get the users inside Voice Channel 1. I'm using Node 17 and DiscordJS 13
This is my code:
message.guild.channels.fetch(channelID, {cache: false, force: true}).then(channels => {
console.log(channels.members);
});
Also, I tried with this one:
let voiceChannel = client.guilds.cache.get(process.env.DISCORDJS_GUILD_ID).channels.cache.get(process.env.DISCORDJS_CHANNEL_ID);
let membersInChannel = voiceChannel.members;
console.log(membersInChannel);
But, it always return the voice channel users that joined when I start the node app. If someone leaves the voice channel, it keeps showing him in the console.log when I say something to the bot in #general. How can I achieve this?