forEach isn't a function (it is!)

I get this error:

(node:1233) UnhandledPromiseRejectionWarning: TypeError: bot.guilds.forEach is not a function

A user said that bot.guilds is the main error since it’s not a function/defined. i might need some spoonfeeding on this one, folks

 bot.guilds.forEach(g => { // what do i change bot.guilds to?
    g.fetchInvites().then(guildInvites => {
      invites[g.id] = guildInvites;
    });
  });
});

Did you login before running this?

1 Like

I’m going to assume that you’ve updated discord.js to v12 and haven’t fully updated your code, in which case the code would be

bot.guilds.cache.forEach(g => {
    g.fetchInvites().then(guildInvites => {
      invites[g.id] = guildInvites;
    });
  });
});
2 Likes

yup…
i need to make this 20 characters smh

oh thanks! i found the code in here

I still get an error.

Full code:

  // To compare, we need to load the current invite list.
  member.guild.fetchInvites().then(guildInvites => {
    // This is the *existing* invites for the guild.
    const ei = invites[member.guild.id];
    // Update the cached invites for the guild.
    invites[member.guild.id] = guildInvites;
    // Look through the invites, find the one for which the uses went up.
    const invite = guildInvites.cache.find(i => ei.get(i.code).uses < i.uses);
    // This is just to simplify the message being sent below (inviter doesn't have a tag property)
    const inviter = bot.users.cache.get(invite.inviter.id);
    // Get the log channel (change to your liking)
    const logChannel = bot.channels.cache.get('718585075171852374');
    // A real basic message with the information we need. 
    logChannel.send(`${member.user.tag} joined using invite code ${invite.code} from ${inviter.tag}. Invite was used ${invite.uses} times since its creation.`);
  });

(node:104) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘find’ of undefined
at /home/runner/zfips-bg/index.js:93:39
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:104) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

still got an error, check replies i sent from another dude

@everyone I got the code working, don’t worry people! I’m going to end it, thanks to those you tried helping!

did you just do @everyone on glitch support? lol

1 Like