Reputation: 3
Currently new to coding Discord bots, and was following along with an online tutorial.
I'm stuck on trying to get the client's message method to log the message that the user typed.
Here's my code:
require('dotenv').config();
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILD_MESSAGES"] });
client.on('ready', () => {
console.log(`${client.user.tag} has logged in`);
});
client.on('message', (msg) => {
console.log(msg.content);
});
client.login(process.env.TOKEN);
The tutorial is a bit outdated since Discordjs has been updated, and I'm not sure if the problem has to do with the intent or something else.
The bot is able to login to the server and shows up as online, with the console registering the login.
However, the console is never able to log any messages sent. Any help would be appreciated.
Upvotes: 0
Views: 1095
Reputation: 86
You need to include both intents:
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
You can still use client.on('message')
but it will come with a DEPRACATED
warning, so as of v13 you should use client.on('messageCreate')
Upvotes: 1