What is the best way to list the members inside a voice channel ?

Hello

I would like to know the best way to list all members inside a voice channel. Does the property "members" is fully reliable ?
Right now I have this code but I wanted to be sure that's the correct way
const channel = await guild.channels.fetch("<id>")
                        .catch( err => {
                            if (err.status === 404) {
                                return null;
                            }

                            throw err;
                        });
                    if (channel?.type !== ChannelType.GuildVoice) {
                        throw new Error("Not a voice channel");
                        return;
                    } else if (channel.members.size > 0) {
                        throw new Error("Some users are still in voice channel");
                        return;
                    }


Versions

  • discord.js : 14.15.3
  • node.js : 20.14.0
Was this page helpful?