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.`);
});
});
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
This is the error message :
I am using Discord.js version 12.5.3 It would be great if someone can help me out :D
CodePudding user response:
const firstInvites = await guild.fetchInvites();
// ...
member.guild.fetchInvites().then(newInvites => {