Created
October 6, 2021 03:55
-
-
Save diegofcornejo/a2ff9e5107829c296986afba169dc10f to your computer and use it in GitHub Desktop.
Discord get all members in a guild (server)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Client, Intents } = require('discord.js'); | |
// const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] }); | |
const client = new Client({ intents: [Intents.FLAGS.GUILD_MEMBERS] }); | |
client.on('ready', () => { | |
console.log(`Logged in as ${client.user.tag}!`); | |
const guild = client.guilds.cache.get('GUILD_ID'); | |
// Fetch and get the list named 'members' | |
guild.members.fetch().then(members => { | |
// Loop through every members | |
members.forEach(member => { | |
// Do whatever you want with the current member | |
// console.log(member.user.username) | |
console.log(member.user) | |
}); | |
client.destroy(); | |
}); | |
}); | |
client.on('interactionCreate', async interaction => { | |
if (!interaction.isCommand()) return; | |
if (interaction.commandName === 'ping') { | |
await interaction.reply('Pong!'); | |
} | |
}); | |
client.login('token'); | |
//get avatar | |
//https://cdn.discordapp.com/avatars/{user_id}/{user_avatar}.png | |
//User { | |
// id: '489192723132317696', | |
// bot: false, | |
// system: false, | |
// flags: null, | |
// username: 'MetalWarrior', | |
// discriminator: '5961', | |
// avatar: 'd2fa2e47033391492597d66e6ef56ab7' | |
//} | |
//https://cdn.discordapp.com/avatars/489192723132317696/d2fa2e47033391492597d66e6ef56ab7.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment