Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the list of all user on a server discord.js

I'm trying to get all users from my server with a bot using discord.js, I wrote this code but it's not working, it's telling me : TypeError: client.guilds.get is not a function. Here is my code :

'use strict';
const Discord = require('discord.js');
const client = new Discord.Client();
const list = client.guilds.get("myServerID"); 
list.members.forEach(member => console.log(member.user.username)); 
client.login('myTokenID');

Thanks

like image 978
François Mari Avatar asked May 07 '20 17:05

François Mari


People also ask

What is a Discord Guild ID?

Guilds in Discord represent an isolated collection of users and channels, and are often referred to as "servers" in the UI. So guilds are basically servers and guildId is a unique server identifier. Follow this answer to receive notifications.

How do I find my Discord Guild ID?

Find your Guild ID (Server ID) In Discord, open your User Settings by clicking the Settings Cog next to your user name on the bottom. Go to Appearance and enable Developer Mode under the Advanced section, then close User Settings. Open your Discord server, right-click on the server name, then select Copy ID.


1 Answers

Since discord.js v12 you now need to access the guilds collection using .cache and I can also see that you're trying to access the members collection so your solution would be:

'use strict';
const Discord = require('discord.js');
const client = new Discord.Client();
const list = client.guilds.cache.get("myServerID"); 
list.members.cache.forEach(member => console.log(member.user.username)); 
client.login('myTokenID');
like image 61
Syntle Avatar answered Nov 09 '22 13:11

Syntle