discord.js: Client is not receiving 'interactionCreate' and 'messageCreate' events

Please describe the problem you are having in as much detail as possible: My Discord Bot is not receiving ‘interactionCreate’ and ‘messageCreate’ events. I have latest version of discord.js installed (version number below). The ‘message’ event is working fine. My command is registered correctly and is visible in Discord.

Include a reproducible code sample here, if possible:

const Discord = require('discord.js');
const { token } = require('./config.json');

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

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

client.on('interactionCreate', async interaction => {
	console.log(interaction)
	if (!interaction.isCommand()) return;

	if (interaction.commandName === 'ping') {
		await interaction.reply('Pong!');
	}
});

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

client.login(token);

Further details:

  • discord.js version: 12.5.3
  • Node.js version: v16.6.1
  • npm version: 7.20.3
  • Operating system: Windows 11 (21H2)
  • Issue priority: High

Relevant client options:

  • gateway intents: GUILDS, GUILD_MESSAGES

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

Just so everyone is aware. The issue on v13 is actually a fault of the tutorial. In the tutorial, the code (directly from the repo) doesn’t provide the correct intents.

If you change the client initialisation to the code below, it will work:

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

I reset INTERACTIONS ENDPOINT URL to be nothing when using dicord.js. Everything is OK now.

I solved this problem just now. I have the same problem but maybe for a different reason. It’s nothing about the code in my situation.

Before I use discord.js, I use the original API here. And I set the INTERACTIONS ENDPOINT URL as the tutorial described official tutorial

Then I started to use discord.js. But interactionCreate cannot work.

I reset INTERACTIONS ENDPOINT URL to be nothing. Everything is OK now.

1650422997(1)

I hope this will help you~

I have same problem with you Further details:

discord.js version: 13.2.0-dev.1628813079.f1d5ffc node.js version: v16.6.2 npm version: 7.20.3

At this point in time, the guide is meant to be used for creating v13 bots. v13 hasn’t been completely released yet, you may install a pre-release by using npm install discord.js@dev. The guide for v12 is accessible at https://v12.discordjs.guide, however, it is advised to start making your bots compatible with v13 as early as possible, and this includes creating new ones.

Your discord.js version doesn’t have these events. They belong to version 13!

Try using interaction intead of interactionCreate, worked for me:

client.on('interaction', (interaction) => {
  console.log(interaction)
})

Yes, it’s deprecated, but for some reason it’s working 🤔

I have the same problem in my case, I was reviewing the permission and scopes of the bot when I generate the link to invite on my server because when I invite the bot like admin the problem is solved. So just try to change the scopes.