Discord.js - guildMemberUpdate 不会被调用,除非 Bot 用户更改 [英] Discord.js - guildMemberUpdate not being called except on Bot user changes

查看:17
本文介绍了Discord.js - guildMemberUpdate 不会被调用,除非 Bot 用户更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码,guildMemberUpdate 事件根本不需要任何用户修改,除了机器人用户.什么可能导致了这种变化,我该如何解决这个问题?

VSC 与最新的 npm 安装 discord.js.在 Discord 上也启用了网关意图.

client.on('guildMemberUpdate', (oldMember, newMember) => {//如果用户有角色则触发if (newMember.roles.cache.some(r => r.name === "TEST_ROLE")) {尝试 {//东西} 捕捉(错误){//东西}}})

解决方案

您似乎没有启用公会成员意图!要启用,请转到:

With the following code, the guildMemberUpdate event does not call for any user modification at all except for the bot user. What could have caused this change, and how do I troubleshoot this?

VSC with latest npm install of discord.js. Enabled the gateway intents on Discord, too.

client.on('guildMemberUpdate', (oldMember, newMember) => {
  // Fire if user has a role
  if (newMember.roles.cache.some(r => r.name === "TEST_ROLE")) {
    try {
      // stuff
    } catch(err) {
      // stuff
    }
  }
})

解决方案

It looks like you did not enable Guild Members Intent! To enable, go to: https://discord.com/developers/applications

Now click on your bot application.

Click on "Bot" on the left panel.

Scroll down until you see "Privileged Gateway Intents".

Below that are two toggles.

Toggle "Guild Members Intent" and save.

Hoped this helped you!

Further reading: https://discord.com/developers/docs/topics/gateway

这篇关于Discord.js - guildMemberUpdate 不会被调用,除非 Bot 用户更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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