活动成员角色更新

时间:2021-01-07 03:55:02

标签: javascript discord.js roles member cargo

我正在尝试制作一个事件,当有人在管理员允许的情况下向其他成员提供职位或将职位放在自己身上时,机器人将识别并惩罚该成员

(但它在执行时没有确认或激活该事件,并且控制台上也没有错误)...

const { Listener } = require("..")
const { RichEmbed, Permissions } = require("discord.js")

let AntiRaidPerm = [
  'ADMINISTRATOR',
  'KICK_MEMBERS',
  'BAN_MEMBERS',
  'MANAGE_CHANNELS',
  'MANAGE_ROLES',
  'MANAGE_EMOJIS',
  'MANAGE_GUILD'
]
module.exports = class MemberRoleUpdate extends Listener {
  constructor (client) {
    super(client)
    this.events = {
      memberRoleUpdate: this.memberroleupdate
    }
  }

  async memberroleupdate (role) {
    if (!this.client.db || !this.client.db.mongoose.connection) return
    if (!role.guild || !role.guild.id) return

    let doc = await this.client.db.guilds.get(role.guild.id)

    const fetchedLogs = await role.guild.fetchAuditLogs({
      limit: 1,
        type: 'MEMBER_ROLE_UPDATE',
    });

    const RoleLog = fetchedLogs.entries.first();

    const { executor, target } = RoleLog;
    
    if( executor.id === this.client.user.id ) return;
    if(executor.id === role.guild.owner) return;

    const adminPerm = new Permissions(target.permissions)
    const adminremove = role.guild.roles.get(target.id)

    if(adminPerm.has('ADMINISTRATOR') === true) {
      const docban = await this.client.db.usersban.get(executor.id)
  
      docban.ban.name = executor.tag
      docban.ban.id = executor.id
  
      docban.ban.counta = docban.ban.counta +1
  
      await docban.save()
  
      let count1 = `${docban.ban.counta}`
      let limit = `${doc.antiraid.alimit}`
      let msg = "Anti-Raid ativado! O usuário {member}"
      const newMsg = msg.replace("{member}", executor.tag);
  
      let warnEmbed = new RichEmbed()
          .setColor("#f7002c")
          .setDescription(newMsg + " foi banido!");

        if(count1 >= limit) {

          role.guild.member(executor).ban(`Proteção de Cargos ativada - \'${executor.username}\' foi banido!`).then(async msg => {
            role.guild.channels.get(doc.antiraid.antilog).send(warnEmbed).catch(()=>{})

            console.log('Estou banindo')

            const perm = new Permissions(adminremove.permissions);
            adminremove.setPermissions(perm.remove('ADMINISTRATOR', ))

            role.guild.roles.forEach(async(role) => {
              let botrole = role.guild.roles.find("name", "The Anti Raiding")

                if(role.position === botrole.position) return;
                if(role.position > botrole.position) return;
          
              if (role.hasPermissions(AntiRaidPerm)) {

              role.setPermissions(perm.remove(AntiRaidPerm))
            }})
          }).catch(console.error)
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

新的网关意图

去年,即 2020 年 10 月 27 日,Discord 实施了新的网关意图限制,这导致在获取包含 GUILD_MEMBER 意图的事件时出现问题。 Lioness100 的完整解释可以在 here 找到。通俗地说,你没有选择正确的意图,这意味着你的 Discord 机器人不会收到某些事件,例如 guildMemberUpdate,这是你想要的

解决方案?

要接收这些事件,您需要通过 Discord 开发者门户打开它们。为此,请转到 https://discord.com/developers/applications 并找到您的应用程序。通常,您的机器人的用户名是应用程序的名称。选择应用程序后,转到右侧边栏上的“Bot”选项卡并向下滚动到 Privileged Gateway Intents。勾选两个框,如下所示,然后点击“保存更改”。你的机器人应该接收事件 Privileged Gateway Intents