Events.MessageCreate don't work

const { Events } = require('discord.js'); module.exports = { name: Events.MessageCreate, execute() { console.log('message'); }, }; this event is successfully loaded but don't work. when i send message totally nothing was happening. 0 errors or something other
5 Replies
d.js toolkit
d.js toolkit12mo 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! - Marked as resolved by OP
Danial
Danial12mo ago
Probably missing intents or partials, where is this message being sent? And show your client constructor
n4a
n4aOP12mo ago
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, GatewayIntentBits, ActivityType } = require('discord.js');
const { token } = require('./data/config.json');

const client = new Client({
intents: [GatewayIntentBits.Guilds],

presence: {
status: "dnd",
activities: [{
intents: [GatewayIntentBits.Guilds],
name: "JoinCode.eu",
type: ActivityType.Custom,
}],
}
});

client.commands = new Collection();
const foldersPath = path.join(__dirname, 'slashcommands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
console.log(`[ 📄 ] Komenda ${file} została pomyślnie załadowana!`);
} else {
console.log(`[ ❌ ] W komendzie ${file} w ${filePath} brakuje wymaganej właściwości "data" lub "execute"!`);
}
}
}

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
console.log(`[ 📄 ] Event ${file} został pomyślnie załadowany!`);
} else {
client.on(event.name, (...args) => event.execute(...args));
console.log(`[ 📄 ] Event ${file} został pomyślnie załadowany!`);
}
}

client.login(token).catch(error => {
console.error(`[ ❌ ] Podczas próby połączenia się z botem wystąpił błąd!`);
process.exit(0);
});
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, GatewayIntentBits, ActivityType } = require('discord.js');
const { token } = require('./data/config.json');

const client = new Client({
intents: [GatewayIntentBits.Guilds],

presence: {
status: "dnd",
activities: [{
intents: [GatewayIntentBits.Guilds],
name: "JoinCode.eu",
type: ActivityType.Custom,
}],
}
});

client.commands = new Collection();
const foldersPath = path.join(__dirname, 'slashcommands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
console.log(`[ 📄 ] Komenda ${file} została pomyślnie załadowana!`);
} else {
console.log(`[ ❌ ] W komendzie ${file} w ${filePath} brakuje wymaganej właściwości "data" lub "execute"!`);
}
}
}

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
console.log(`[ 📄 ] Event ${file} został pomyślnie załadowany!`);
} else {
client.on(event.name, (...args) => event.execute(...args));
console.log(`[ 📄 ] Event ${file} został pomyślnie załadowany!`);
}
}

client.login(token).catch(error => {
console.error(`[ ❌ ] Podczas próby połączenia się z botem wystąpił błąd!`);
process.exit(0);
});
Danial
Danial12mo ago
Yeah, missing GuildMessages or DirectMessages and Channel partial depending on where the message was sent, also why do you have intents in the activities array
n4a
n4aOP12mo ago
tysm, now its working
Want results from more Discord servers?
Add your server