Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
TypeError: Cannot read property 'fetch' of undefined Discord.js for Invite Logger

This is the code which I am currently using for the Invite Logger and when I run it, it shows an error stating that it cannot read the 'fetch' property.

const invites = new Map();
const wait = require("timers/promises").setTimeout;

client.on("ready", async() => {
  await wait(1000);

  client.guilds.cache.forEach(async(guild) => {
    const firstInvites = await guild.invites.fetch();
    invites.set(guild.id, new Map(firstInvites.map((invite) => [invite.code, invite.uses])));
  });
});

client.on("inviteDelete", (invite) => {
  invites.get(invite.guild.id).delete(invite.code);
});

client.on("inviteCreate", (invite) => {
  invites.get(invite.guild.id).set(invite.code, invite.uses);
});

client.on("guildMemberAdd", member => {
  member.guild.invites.fetch().then(newInvites => {
    const oldInvites = invites.get(member.guild.id);
    const invite = newInvites.find(i => i.uses > oldInvites.get(i.code));
    const inviter = client.users.cache.get(invite.inviter.id);
    const logChannel = member.guild.channels.cache.find(channel => channel.name === "bot-testing");
    inviter
      ?
      logChannel.send(`${member.user.tag} joined using invite code ${invite.code} from ${inviter.tag}. Invite was used ${invite.uses} times since its creation.`) :
      logChannel.send(`${member.user.tag} joined but I couldn't find through which invite.`);
  });
});

This is the error message :

enter image description here

I am using Discord.js version 12.5.3 It would be great if someone can help me out :D

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

On v12.5.3, there is no GuildInviteManager.fetch() function, you'll have to use Guild.fetchInvites.

https://discord.js.org/#/docs/main/12.5.3/class/Guild?scrollTo=available

    const firstInvites = await guild.fetchInvites();
// ...
    member.guild.fetchInvites().then(newInvites => {
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!