discord.js Check user invites without leaves

混江龙づ霸主 提交于 2020-08-25 06:07:49

问题


I am trying to get how many members a certain member has invited. The code below works, but it counts all invited members including members that have left. I want it to show only the amount of invited members which are still on the server.

var user = null;
user = message.mentions.members.first() || 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'];
        userInviteCount - invite['left'];
    }

    message.reply(`You have ${userInviteCount} invites.`);
});

回答1:


Idea 1: Get the userID of each userInviteCount and check if they are still in the server via a loop.

Idea 2: Discord.JS has no function to check what invite link a member came from, so you can sadly not just cycle through all members and check whether or not they came from your desired invite link. What bots like InviteManager does is, that they detect when a member joins, and then they check all valid invite links for an increase in uses. Then, the one that goes up by 1 will be detected as the used invite link.



来源:https://stackoverflow.com/questions/63214920/discord-js-check-user-invites-without-leaves

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!