DiscordJS V 14 Not able to receive data for MessageCreate

pxldevv
HOBBY

a year 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.

0 Replies

pxldevv
HOBBY

a year ago

N/A


pxldevv
HOBBY

a year ago

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


pxldevv
HOBBY

a year ago

but nothing works


pxldevv
HOBBY

a year ago

and yes I enabled intents in the discord Developer Portal.


pxldevv
HOBBY

a year ago

1245270695663894500


pxldevv
HOBBY

a year ago

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


pxldevv
HOBBY

a year ago

And I simplified it as much as possible too.


pxldevv
HOBBY

a year 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
HOBBY

a year ago

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


pxldevv
HOBBY

a year ago

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


a year ago

@PixelZero You need GatewayIntentBits.GuildMessages


pxldevv
HOBBY

a year ago

I had that earlier but let me try again.


a year ago

MessageContent
GuildMessages

… are required


pxldevv
HOBBY

a year ago

oh yeah the code snippit has it at the top


pxldevv
HOBBY

a year ago

the first one


a year ago

Does it work? :D


pxldevv
HOBBY

a year ago

nope


a year ago

Hmm wierd


pxldevv
HOBBY

a year ago

yeah


a year ago

Try ask in the discord.js server.


pxldevv
HOBBY

a year ago

okay


pxldevv
HOBBY

a year ago

the discord developers?


a year ago

No .gg/djs