Home > front end >  Discord (v13) Bot Not Detecting Events (Node 16.10.0)
Discord (v13) Bot Not Detecting Events (Node 16.10.0)

Time:10-06

I've set up a bot with Discord.js version 13.2 and Node version 16.10.0. I've verified this using 'node -v' in the terminal and checking the Discord version using discord.version. I've pasted my code below. My bot is added to my server using Admin permissions (8) and using the Bot scope.

When I run the code my bot connects. I can see it go online on my server. I get the Ready message in the terminal. But when I type a message into any channel on Discord, I don't get the event. I used an old bot I had working in Discord.js version 12 and using Node version 14 (running on a separate laptop), and I was able to get it detecting messages I send in my server. I've been wracking my brain over anything I could have done but I can't figure out what's wrong here.

const {Client, Intents} = require('discord.js')
const {token} = require('./config.json')

//const client = new Client({intents: [Intents.FLAGS.GUILDS]})
var client = new Client({autoReconnect:true,intents:[Intents.FLAGS.GUILDS]})


client.on('ready',()=> {
    console.log("Ready")
})
.on("error",(err)=> {
    console.log(err)
})
.on('invalidated',()=> {
    console.log("Client invalid.")
})
.on('guildUnavailable',(guild)=> {
    console.log("Guild unavailable.")
})

// Trying both 'message' and 'messageCreate' just in case
.on('message',(msg)=> {
    console.log(msg.content)
})
.on('messageCreate',(msg)=> {
    console.log(msg.content)
})

.on('messageReactionAdd',(reaction,user)=> {
    console.log("reaction!")
})


// Connect to Discord
client.login(token)

CodePudding user response:

You need GUILD_MESSAGES intent to detect messages

var client = new Client({
  autoReconnect: true,
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES
  ]
})

and reactions need GUILD_MESSAGE_REACTIONS intents

var client = new Client({
  autoReconnect: true,
  intents: [
    Intents.FLAGS.GUILDS, 
    Intents.FLAGS.GUILD_MESSAGES, 
    Intents.FLAGS.GUILD_MESSAGE_REACTIONS
  ]
})
  • Related