繁体   English   中英

当 Discord.js 检测到添加的特定角色时删除另一个角色

[英]Removing another role when a specific role added is detected with Discord.js

我想知道是否有人可以帮助我使用我当前机器人的 Discord.js 代码片段。

我希望在下面的这些代码行中添加删除角色 --- 所以基本上我的机器人正在检测特定于添加的这个角色的角色更改何时发生。 然后一旦发生,它就会剥夺其中一个角色——如果这有意义吗?

if
  (!oldMem.roles.find(x => x.name === "Inactive") && newMem.roles.find(x => x.name === "Inactive"))
      client.channels.get("547932494259814410").send(`:bell: ${newMem} THere is a new inactive <@&662373687726440461>...`);

我想从用户中删除的角色是 560860499894337538 的角色 ID - 虽然不是每个人都会拥有这个角色,所以我希望这可以在没有 BOT 出错的情况下完成。

我添加的代码将尝试找到您要删除的角色,如果找到则将其删除。

if (!oldMem.roles.find(x => x.name === "Inactive") && newMem.roles.find(x => x.name === "Inactive")) {
    client.channels.get("547932494259814410").send(`:bell: ${newMem} There is a new inactive <@&662373687726440461>...`);

    const role = message.member.roles.get('560860499894337538');

    if (role) newMem.roles.remove(role).catch(console.log);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM