Here is a code I found on another question
client.on('message', message => {
if(message.content === "n!invites"){
var user = message.author;
message.guild.fetchInvites()
.then
(invites =>
{
const userInvites = invites.array().filter(o => o.inviter.id === user.id);
var userInviteCount = 0;
for(var i=0; i < userInvites.length; i++)
{
var invite = userInvites[i];
userInviteCount += invite['uses'];
}
message.reply(`You have ${userInviteCount} invites.`);
}
)
}
});
It gets every invite links from the guild using
message.guild.fetchInvites()
and finds an invite link that was created by the user which is the author, in this case, using a filter
const userInvites = invites.array().filter(o => o.inviter.id === user.id);
Using a for loop, it adds the amount of invites the user has until the invites the user has matches it.
var userInviteCount = 0;
for(var i=0; i < userInvites.length; i++)
{
var invite = userInvites[i];
userInviteCount += invite['uses'];
}
Then it adds the amount of uses to the userInviteCount statement which will be 0 if there is no invite found made by the user or the user has not invited anybody to the server.
Finally is sends a reply with the amount of invites the user has
message.reply(`You have ${userInviteCount} invites.`);
It is in a Template String so you don't have to put + but instead put ${expression} which is userInviteCount, so the amount of invites the user has.