messageCreate.js not working

Please note I am using a slash command, command and event handler.
//messageCreate.js
require('dotenv').config();
module.exports = {
name: 'messageCreate',
execute(message, client){
const prefix = process.env.PREFIX;
console.log('Message')
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd));
if(command) command.execute(client, message, args);
}
}
//messageCreate.js
require('dotenv').config();
module.exports = {
name: 'messageCreate',
execute(message, client){
const prefix = process.env.PREFIX;
console.log('Message')
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd));
if(command) command.execute(client, message, args);
}
}
Event handler + client.events = new Collection:
//inside index.js
const eventsPath = path.join(__dirname, 'Events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const event_filePath = path.join(eventsPath, file);
const event = require(event_filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
//inside index.js
const eventsPath = path.join(__dirname, 'Events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const event_filePath = path.join(eventsPath, file);
const event = require(event_filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
39 Replies
Mozzy
Mozzy3y ago
What is not working? messageCreate won't fire for application commands
PAdventures
PAdventuresOP3y ago
for normal commands
Mozzy
Mozzy3y ago
message.content will be empty if you don't have the Message content intent
PAdventures
PAdventuresOP3y ago
Message content intent? i used a console.log when a messageCreate happens and nothing shows up in the console
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
no?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
how do i use them
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs3y ago
Tag suggestion for @PAdventures: • Websocket intents limit events and decrease memory usage: learn more • See what intents you need here
PAdventures
PAdventuresOP3y ago
how do i add multiple intents const client = new Client({ intents: [GatewayIntentBits.GuildMessages.MessageContent], partials: [Partials.Channel] }); not work
Mozzy
Mozzy3y ago
[Intent1, Intent2]
PAdventures
PAdventuresOP3y ago
🤦‍♂️
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
k how do i do that
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
i have already done that and nothing happend
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
const client = new Client({ intents: [GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent], partials: [Partials.Channel] });
const client = new Client({ intents: [GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent], partials: [Partials.Channel] });
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
already enabled messageCreate.js
chewie
chewie3y ago
you are missing the Guilds intent.
PAdventures
PAdventuresOP3y ago
k
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
Message
D:\PA_Admin Backup\Events\messageCreate.js:11
const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd));
^

TypeError: Cannot read properties of undefined (reading 'commands')
at Object.execute (D:\PA_Admin Backup\Events\messageCreate.js:11:32)
at Client.<anonymous> (D:\PA_Admin Backup\index.js:55:44)
at Client.emit (node:events:520:28)
at MessageCreateAction.handle (D:\PA_Admin Backup\node_modules\discord.js\src\client\actions\MessageCreate.js:23:14)
at Object.module.exports [as MESSAGE_CREATE] (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
at WebSocketShard.onMessage (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
at WebSocket.onMessage (D:\PA_Admin Backup\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:520:28)
Message
D:\PA_Admin Backup\Events\messageCreate.js:11
const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd));
^

TypeError: Cannot read properties of undefined (reading 'commands')
at Object.execute (D:\PA_Admin Backup\Events\messageCreate.js:11:32)
at Client.<anonymous> (D:\PA_Admin Backup\index.js:55:44)
at Client.emit (node:events:520:28)
at MessageCreateAction.handle (D:\PA_Admin Backup\node_modules\discord.js\src\client\actions\MessageCreate.js:23:14)
at Object.module.exports [as MESSAGE_CREATE] (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
at WebSocketShard.onMessage (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
at WebSocket.onMessage (D:\PA_Admin Backup\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:520:28)
chewie
chewie3y ago
client isnt defined or rather the content of client isnt
PAdventures
PAdventuresOP3y ago
execute(message, client, commands)?
chewie
chewie3y ago
show how you pass client in other words your event handler
PAdventures
PAdventuresOP3y ago
const eventsPath = path.join(__dirname, 'Events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const event_filePath = path.join(eventsPath, file);
const event = require(event_filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
const eventsPath = path.join(__dirname, 'Events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const event_filePath = path.join(eventsPath, file);
const event = require(event_filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
chewie
chewie3y ago
you are not passing client to the method either do that or just use message.client
PAdventures
PAdventuresOP3y ago
k thanks for the help guys
.setDescription(`${message.author.user.tag} used **/${message.author.commandName}** in <#${message.author.channel.id}>`)
.setDescription(`${message.author.user.tag} used **/${message.author.commandName}** in <#${message.author.channel.id}>`)
How do i get this to work? TypeError: Cannot read properties of undefined (reading 'tag')
chewie
chewie3y ago
message.author is already a user and message.author.commandName doesnt exist
PAdventures
PAdventuresOP3y ago
message.commandName?
chewie
chewie3y ago
no why do you think that exists
PAdventures
PAdventuresOP3y ago
how do get the name of the command that the message author used then?
chewie
chewie3y ago
you parse it yourself thats why you shouldnt use message commands
PAdventures
PAdventuresOP3y ago
k
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
chewie
chewie3y ago
You are late, already resolved.
Want results from more Discord servers?
Add your server