Search code examples
javascriptnode.jsdiscord.js

Discord.JS V13 client.on messagecreate not firing


I've just recently finished upgrading my Discord.js bot to v13 and now the client.on(messageCreate) function doesn't fire? None of my code in it ever runs and I'm really confused as to why.

Before anybody asks, I have already set my intents.

const client = new Discord.Client({
  intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES ],
  partials: ['MESSAGE', 'CHANNEL', 'REACTION'], 
});

I have two functions, the client.on fires but the message doesn't

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageCreate', msg => {
  console.log(anything)
}

Solution

  • Make sure you include GUILDS in your list of intents. Otherwise, the bot can only see messages that have been sent after the bot itself sent a message.

    In my case, I needed to set these:

    partials: ['MESSAGE', 'CHANNEL', 'REACTION']
    intents: ['DIRECT_MESSAGES', 'DIRECT_MESSAGE_REACTIONS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'GUILDS']
    

    but the particulars will vary by your use case.