1

I am trying out discord.js version 13.1.0 and I am following discord's guide on how to setup a bot. I have followed all the steps. When I have the bot running, and I send a message or a command into the server, nothing gets printed to the console. Any ideas?

My code:

const { Client, Intents } = require("discord.js");

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

client.once("ready", () => {
  console.log("Ready!");
});

client.on("interactionCreate", (interaction) => {
  console.log(interaction);
});

client.login(process.env.TOKEN);
NaeNate
  • 185
  • 9
  • 1
    A message will not emit the interaction event, have you tried using `messageCreate` – Elitezen Aug 18 '21 at 13:21
  • Does this answer your question? "[message event listener not working properly](https://stackoverflow.com/q/64394000/90527)", "[Having trouble sending a message to a channel with Discord.js](https://stackoverflow.com/q/68795635/90527)", "[Discord bot is not replying to messages](https://stackoverflow.com/q/68804831/90527)". – outis Oct 30 '21 at 22:19

1 Answers1

2

From the Discord Developer Portal:

An Interaction is the message that your application receives when a user uses an application command or a message component.

By an application command is meant a special type of command, that you have to register against the Discord API. To learn more about application commands, read this.

From the discord.js docs main page, how to register an application (slash) command:

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');

const commands = [{
  name: 'ping',
  description: 'Replies with Pong!'
}]; 

const rest = new REST({ version: '9' }).setToken('token');

(async () => {
  try {
    console.log('Started refreshing application (/) commands.');

    await rest.put(
      Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
      { body: commands },
    );

    console.log('Successfully reloaded application (/) commands.');
  } catch (error) {
    console.error(error);
  }
})();

However if you are looking for a way to reply to (or just capture) a normal message sent in a TextChannel, you are probably looking for the messageCreate event.

client.on("messageCreate", (message) => {
    console.log(message);
});

Also note that to receive messageCreate event, you need GUILD_MESSAGES intent.

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
Skulaurun Mrusal
  • 2,792
  • 1
  • 15
  • 29