A
A
AlmondPark336092021-08-05 19:49:21
JavaScript
AlmondPark33609, 2021-08-05 19:49:21

How to find out who invited a user to the discord.js server?

Tried the code:

client.on('guildMemberAdd', member => {
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.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 = client.users.cache.find(invite.inviter.id);
    console.log(inviter.tag)
    })
})

Gives an error Cannot read property 'get' of undefined
Maybe I'm dumb...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question