discord.js检查用户邀请时不假 [英] discord.js Check user invites without leaves

查看:142
本文介绍了discord.js检查用户邀请时不假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让某个成员邀请了多少成员。下面的代码有效,但是它计算所有邀请的成员,包括离开的成员。
我希望它仅显示仍在服务器上的受邀请成员的数量。

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:
获取以下项的用户ID

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

想法2:
Discord.JS没有功能来检查成员来自哪个邀请链接,因此,每个userInviteCount并通过循环检查它们是否仍在服务器中。遗憾的是,您不仅可以循环浏览所有成员并检查他们是否来自您想要的邀请链接。
像InviteManager这样的漫游器所做的是,它们检测成员何时加入,然后检查所有有效的邀请链接以增加使用量。然后,上升1的那个将被检测为使用的邀请链接。

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.

这篇关于discord.js检查用户邀请时不假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆