I try to make a simple bot that just lists all members that have a specific role.
I went through most of the similar questions I could find, but their answers seem outdated. So I tried this but end up with the result 'undefined', although the role exists.
const discord = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new discord.Client(
{ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS
] });
const prefix ="!";
const MemberID = "912852591023628371";
client.on('ready', () => {
console.log('Connected to the bot');
});
client.on('messageCreate', msg => {
if (msg.content === 'hi') {
msg.reply('Hi to you too!');
}
});
client.on('messageCreate', async message => {
if (message.content === prefix + 'list') {
let list = client.guilds.cache.get(MemberID);
console.log(list);
}
}
);