help with invite tracker needed

hey, i'm not that experienced with coding discord bots and i need help with an invite tracker. right now i have a /invites command that tells the user how many invites they have. it works fine but i want the invites to only track members that are in the server. so if a member that they have invited leaves the server, their invites go down. i'm not even show how i'd go about creating that, just looking for some direction on how i'd do something like this. here's how invites are currently tracked:
const invites = await guild.invites.fetch();
const userInvites = invites.filter(invite => invite.inviter && invite.inviter.id === user.id);
let inviteCount = 0;
userInvites.forEach(invite => {
inviteCount += invite.uses;
});
const invites = await guild.invites.fetch();
const userInvites = invites.filter(invite => invite.inviter && invite.inviter.id === user.id);
let inviteCount = 0;
userInvites.forEach(invite => {
inviteCount += invite.uses;
});
4 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
5hurn
5hurnOP7mo ago
also please tag me in your response
duck
duck7mo ago
you'd need some means of tracking which invite a given member used discord doesn't provide this info, so you'd basically need to fetch invites everytime guildMemberAdd emits and compare the uses from before and after then you can listen to the guildMemberRemove event to count how many would need to be subtracted from the sum of uses as you have here
5hurn
5hurnOP7mo ago
ok thanks for the help
Want results from more Discord servers?
Add your server