用户收到邀请时添加角色的问题

时间:2020-08-13 19:07:45

标签: node.js discord discord.js

我有这个邀请函脚本,当邀请数达到邀请数时,我该怎么办?

member.guild.fetchInvites().then(guildInvites => {
    const inv = invites[member.guild.id];
    invites[member.guild.id] = guildInvites;
    const invite = guildInvites.find(i => !inv.get(i.code) || inv.get(i.code).uses < i.uses);
    const inviter = bot.users.get(invite.inviter.id);
    const logChannel = member.guild.channels.find(channel => channel.id === "");
    logChannel.send("<@" + member.user.id + "> " + "** joined**" + " invited by " + inviter.tag + `(${invite.uses} invites)`);
    var role= member.guild.roles.find(role => role.name === "Test");
    if(invite.uses == 25) {
        member.inviter.addRole(role);
    }
});

1 个答案:

答案 0 :(得分:0)

您只需要使用invite.inviter(创建邀请的用户)而不是member(加入服务器的成员)。

member.guild.fetchInvites().then(async guildInvites => {
    const inv = invites[member.guild.id];
    invites[member.guild.id] = guildInvites;
    const invite = guildInvites.find(i => !inv.get(i.code) || inv.get(i.code).uses < i.uses);
    const inviter = bot.users.get(invite.inviter.id);
    const logChannel = member.guild.channels.find(channel => channel.id === "");
    logChannel.send("<@" + member.user.id + "> " + "** joined**" + " invited by " + inviter.tag + `(${invite.uses} invites)`);
    if(invite.uses == 25) {
        const role = member.guild.roles.find(role => role.name === "Test");
        const inviterMember = await member.guild.fetchMember(invite.inviter.id);
        inviterMember.addRole(role);
    }
});