Discord bot won’t log messages Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Discord bot won’t log messages without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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.

Answer

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')

We are here to answer your question about Discord bot won’t log messages - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji