(discord.js) How Do I Get All The Members Connected To The Voice Channels Of A Category?
So, i'm making a command called 'movedebat' to move all the members connected to the voice channels of a channel category to a channel dedicated to debates. To achieve my goal, I a
Solution 1:
When you declare
connected_members
, you should use a single function inCollection.filter()
.Collection.filter()
returns another Collection, of whichmembers
is not a property. You'll have to iterate through each channel to get its members.for...in
"iterates over all non-Symbol, enumerable properties of an object" (MDN). In a Collection (Map), the elements aren't properties, but key-value pairs. You can usefor...of
instead in this context.
if (message.member.permissions.missing('ADMINISTRATOR')) return;
const channels = message.guild.channels.filter(c => c.parentID === '497908108803440653' && c.type === 'voice');
for (const [channelID, channel] of channels) {
for (const [memberID, member] of channel.members) {
member.setVoiceChannel('497910775512563742')
.then(() =>console.log(`Moved ${member.user.tag}.`))
.catch(console.error);
}
}
Side note: Use Map.get()
for finding a value from a Collection by its ID.
Post a Comment for "(discord.js) How Do I Get All The Members Connected To The Voice Channels Of A Category?"