AnonymousJan 18, 2024
In this article, we will see how to get the list of all users on a Discord server using discord.js library in JavaScript
To get the list of all users on a Discord server using discord.js library in JavaScript, you can use the Guild.members property.
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
const guildId = 'YOUR_SERVER_ID'; // Replace with your server ID
const guild = client.guilds.cache.get(guildId);
if (!guild) {
console.log('Guild not found');
return;
}
guild.members.fetch().then((members) => {
members.forEach((member) => {
console.log(member.user.username);
});
}).catch(console.error);
});
client.login('YOUR_BOT_TOKEN'); // Replace with your bot token
Make sure to replace 'YOUR\_SERVER\_ID'
with the actual server ID you want to retrieve the user list from, and 'YOUR\_BOT\_TOKEN'
with your Discord bot token.
Keep in mind that you will need to have the necessary permissions for your bot to access the server and fetch the member list.