DiscordJS V 14 Not able to receive data for MessageCreate
pxldevv
HOBBYOP

2 years ago

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

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent] });

client.on("ready", function(){
    console.log(`the client becomes ready to start`);
    console.log(`I am ready! Logged in as ${client.user.tag}!`);
});

client.on("messageCreate", function(message){
    console.log(`a message was created`);
    console.log({message});
});


client.login(token);

I am able to get any other event but anything that has to do with messages just won't work.

23 Replies

pxldevv
HOBBYOP

2 years ago

N/A


pxldevv
HOBBYOP

2 years ago

I've tried to use Events.MessageCreate and other ways


pxldevv
HOBBYOP

2 years ago

but nothing works


pxldevv
HOBBYOP

2 years ago

and yes I enabled intents in the discord Developer Portal.


pxldevv
HOBBYOP

2 years ago

1245270695663894500


pxldevv
HOBBYOP

2 years ago

The problem is I was originally using discord's example code.


pxldevv
HOBBYOP

2 years ago

And I simplified it as much as possible too.


pxldevv
HOBBYOP

2 years ago

// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// When the client is ready, run this code (only once).
// The distinction between `client: Client` and `readyClient: Client` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, readyClient => {
    console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});

// Log in to Discord with your client's token
client.login(token);

pxldevv
HOBBYOP

2 years ago

And then I added the Events.MessageCreate which is refrenced somewhere else.


pxldevv
HOBBYOP

2 years ago

that didn't work so I switched over from the Events of Discord.JS


lasse
PRO

2 years ago

@PixelZero You need GatewayIntentBits.GuildMessages


pxldevv
HOBBYOP

2 years ago

I had that earlier but let me try again.


lasse
PRO

2 years ago

MessageContent
GuildMessages

… are required


pxldevv
HOBBYOP

2 years ago

oh yeah the code snippit has it at the top


pxldevv
HOBBYOP

2 years ago

the first one


lasse
PRO

2 years ago

Does it work? :D


pxldevv
HOBBYOP

2 years ago

nope


lasse
PRO

2 years ago

Hmm wierd


pxldevv
HOBBYOP

2 years ago

yeah


lasse
PRO

2 years ago

Try ask in the discord.js server.


pxldevv
HOBBYOP

2 years ago

okay


pxldevv
HOBBYOP

2 years ago

the discord developers?


lasse
PRO

2 years ago

No .gg/djs


Loading...