0

I wrote this code but the userUpdate part doesn't even trigger when someone changes their username, so I'm thinking I probably forgot to add an intent? Furthermore, would the code work at all if I had the missing intent? Note: I am using v12

const discord = require("discord.js");
const client = new discord.Client({ ws: { intents: 'GUILD_MEMBERS' }});
 
client.on('userUpdate', (oldUser, newUser) => {
    console.log(oldUser);
    console.log(newUser);
    if(newUser.user.username && oldUser.user.username !== newUser.user.username) {
        if(newUser.user.username.includes("test")) {
            newUser.user.ban();
        }
    }
 });
Tom
  • 1
  • 1
  • Does this answer your question? [None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica) – Zsolt Meszaros Apr 11 '22 at 11:35
  • @ZsoltMeszaros No, I tried adding the other intent too and it still doesn't log anything – Tom Apr 11 '22 at 12:16

1 Answers1

0

Switch to v13 because v12 is an old deprecated API version. For v12 you don't need intent in code.

For v13:

You need these intents USER_UPDATE, GUILD_MEMBER_UPDATE, PRESENCE_UPDATE https://discord.js.org/#/docs/discord.js/stable/class/Client?scrollTo=e-userUpdate

Also enable Presence Intent in your discord developer dashboard.

  • The question asks about V12, if you feel like it is a better option to use V13, put it as a comment, since this does not answer the question. Is up to the OP to use the version they want, but commenting an advice is ok. – S. Dre Apr 11 '22 at 15:37
  • The answer above also answer for v12. If you read it – Rohan Kumar Apr 11 '22 at 15:48
  • It says it doesn't need an intent for v12, which is some insight, but it doesn't solve the question. – S. Dre Apr 11 '22 at 15:55
  • in v12 you don't need to mention any intent. But he does need to enable presense intent on discord developer dashboard – Rohan Kumar Apr 11 '22 at 16:09
  • Hmmm I thought that was part of the v13 part, didn't understand it correctly then! – S. Dre Apr 11 '22 at 16:11
  • Those are not intents, those are websocket events – MrMythical Apr 11 '22 at 17:11