Skip to content
Advertisement

How to get users in voice channel without cache in DiscordJS?

I’m trying to get all users connected to a voice channel on my server. When someone talks to a 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:

JavaScript

Also, I tried this one:

JavaScript

But, it always returns 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?

Advertisement

Answer

I’ve had the same problem. Although I added { force: true } as the option in fetch, it always showed the same number of members when I started the app, ignoring the ones who joined/left the channel.

Enabling the GUILD_VOICE_STATES intent solved this. So don’t forget to add it to your client:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement