在发送的特定消息中赋予角色

时间:2021-04-09 13:53:29

标签: discord discord.js

所以我想给一个角色发送特定数量的消息

如果他们设法发送1k 消息,他们将获得特定角色

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

所以如果你知道角色 ID 那么

roleID = "100000000000000001";
let member = message.mentions.members.first();
if(memberHasEnoughMessage && !member.roles.get(roleID)){
    let role = Guild.roles.cache.get(roleID);
    if(member && role){
        member.roles.add(role);
    }
}

如果您不知道角色 ID 而只知道名称,那么

const role = Guild.roles.cache.find(role => role.name === '10k message');

如果你想创建一个新角色(假设有权限 ping 每个人)然后

Guild.createRole( {name:"10k", color: "#f6f61", permissions:["MENTION_EVERYONE"] } );

所以最终的代码应该是这样的

roleID = "100000000000000001";
let member = message.mentions.members.first();
if(memberHasEnoughMessage){
/*
    If you already know the role ID
    let role = Guild.roles.cache.get(roleID);
*/
    let role = Guild.roles.cache.get(roleID);
    ler role = Guild.roles.cache.find(r=> r.name === '1k');
    if(!role){
        await Guild.createRole( {name:"Mentioners", color: "#ff0000", permissions:["MENTION_EVERYONE"] } ).then( (newRole) =>
            role = rnewRole;
        }).catch(console.log);
    }
    if(member && role){
        member.roles.add(role);
    }
}