DiscordJS V14 not catching Event "MessageCreate"

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);
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);
20 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
𖥂 PixelFire 𖥂
[email protected] C:\Users\PixelZero\Documents\dev\PixelBot
[email protected] C:\Users\PixelZero\Documents\dev\PixelBot
node version
v20.14.0
v20.14.0
d.js docs
d.js docs7mo ago
To receive direct message events on "messageCreate" with your bot, you will need: - The DirectMessages gateway intent - The Channel partial setting
𖥂 PixelFire 𖥂
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent], partials: [Partials.Channel]});
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent], partials: [Partials.Channel]});
Updated to this, still no messageCreate being fired.
chewie
chewie7mo ago
You do want the messageCreate to fire from dms, not from a guild channel, right?
𖥂 PixelFire 𖥂
I am trying to see when any message is being fired from a guild in a channel. ^
chewie
chewie7mo ago
Then you need the GuildMessages intent
𖥂 PixelFire 𖥂
Assuming like this?
const { Client, GatewayIntentBits, Partials, Message } = require('discord.js');
const { token } = require('./config.json');

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

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);
const { Client, GatewayIntentBits, Partials, Message } = require('discord.js');
const { token } = require('./config.json');

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

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);
chewie
chewie7mo ago
yes
𖥂 PixelFire 𖥂
I tried that. Still nothing.
chewie
chewie7mo ago
can you log eventFiles above the loop
𖥂 PixelFire 𖥂
I also tried with Events.MessageCreate rq let me look that up 💀
chewie
chewie7mo ago
wait no wrong channel, wasnt meant for you
𖥂 PixelFire 𖥂
oops lol
PhonedLeek25
PhonedLeek257mo ago
@PixelZero this is how I do it
client.on("messageCreate", msg =>
{
console.log("message detected by " + msg.author.tag.toString());
}
)
client.on("messageCreate", msg =>
{
console.log("message detected by " + msg.author.tag.toString());
}
)
can also use async (msg) but im new to javascript and don't know what that does for reference that would like this:
client.on("messageCreate", async (msg) =>
{
console.log("message detected by " + msg.author.tag.toString());
}
)
client.on("messageCreate", async (msg) =>
{
console.log("message detected by " + msg.author.tag.toString());
}
)
like i said im new to this so maybe you just need to not include function(){} and instead do msg => {} or async (msg) => {} if that doesn't work if there's some error message please show it
𖥂 PixelFire 𖥂
No error message for the methods I’ve tried already. I’ll try this in the morning when I get on my pc 👍
PhonedLeek25
PhonedLeek257mo ago
ok 💀
d.js docs
d.js docs7mo ago
:guide: Additional Information: Understanding async/await read more
𖥂 PixelFire 𖥂
That seemed to have worked. It's weird cuz the other code is now working too 💀 idk what fixed it but it's working now thanks for your help.
Want results from more Discord servers?
Add your server