#unable to fetch members

35 messages · Page 1 of 1 (latest)

lime quartzBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

glacial path
#

"discord.js": "^14.9.0",
node: v18.16.0

dense bloom
#

Not all members are cached. If it's a voice based channel, then add GuildVoiceStates inetent. Else fetch all members of the guild.

glacial path
#

replaced the code with

const guild = client.guilds.cache.first();
  const members = guild.members.fetch();
    console.log(`Found members: ${members.map(member => member.displayName).join(", ")}`);
#

still no output in the terminal

#

its giving undefined

subtle nova
#

Fetch returns a promise

glacial path
#

Wdym

formal holly
#

await guild.membres.fetch()

glacial path
#

Didn't work

compact coral
#

They also spelt members wrong

glacial path
#

Adding Await

compact coral
#

Show the code

#

All of it

glacial path
#
import dotenv from "dotenv";
import { Client, GatewayIntentBits } from "discord.js";

dotenv.config();

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent
  ]
});

const channelID = '{channelID-here}'; //general


client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}`);
  setInterval(runFunction, 1);
});

async function runFunction() {
  const channel = client.channels.fetch(channelID);
  const guild = client.guilds.cache.first();
  const members = await guild.members.fetch();
  console.log(`Found ${members.size} members in ${guild.name}:`);
client.login(process.env.BOT_TOKEN);
console.log('bot is online');
#

does it have to do with something related to the client?

compact coral
glacial path
compact coral
glacial path
#

yeah on it

#

thank you so much for your help @compact coral

#

its working now

glacial path
#
import dotenv from "dotenv";
import { Client, GatewayIntentBits } from "discord.js";

dotenv.config();

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.MessageContent
  ]
});

const channelID = '1100170161694183427'; //general
const targetChannelID = '1101092357635579944'; //test

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}`);
  setInterval(runFunction, 60);
});

async function runFunction() {
  const channel = client.channels.fetch(channelID);
  const guild = client.guilds.cache.first();
  const members = await guild.members.fetch();
  const validMembers = members.filter(member => !member.user.bot && member.lastMessageChannelID === channel.id).values();
  if (validMembers.length > 0) {
  const randomIndex = Math.floor(Math.random() * validMembers.length);
  let randomMember = validMembers[randomIndex];
  console.log(`${randomMember.displayName}`);
 // await channel.send(`Congratulations to <@${randomMember}> for being selected randomly!`);
  }
}
client.login(process.env.BOT_TOKEN);
console.log('bot is online');

i updated the code and to convert validMembers to an array i used values() and now i'm being shown this Error [GuildMembersTimeout]: Members didn't arrive in time.

#

did i do the array conversion right?

compact coral
compact coral
viscid wagon
glacial path
glacial path
#

here's the updated code