Why isnt my eventHandler being loaded?

async function loadEvents(client) {
const { loadFiles } = require('../Functions/fileLoader');
const ascii = require("ascii-table")
const table = new ascii().setHeading("Events", "Status");

await client.events.clear();

const Files = await loadFiles("Events");

Files.forEach((file) => {
const event = require(file);

const execute = (...args) => event.execute(...args, client);
client.events.set(event.name, execute);

if(event.rest) {
if(event.once) client.rest.once(event.name, execute);
else
client.rest.on(event.name, execute);
} else {
if(event.once) client.once(event.name, execute);
else
client.on(event.name, execute);
}

table.addRow(event.name, "Online")
})

return console.log(table.toString(), "\nLoaded Events")
}

module.exports = { loadEvents }
async function loadEvents(client) {
const { loadFiles } = require('../Functions/fileLoader');
const ascii = require("ascii-table")
const table = new ascii().setHeading("Events", "Status");

await client.events.clear();

const Files = await loadFiles("Events");

Files.forEach((file) => {
const event = require(file);

const execute = (...args) => event.execute(...args, client);
client.events.set(event.name, execute);

if(event.rest) {
if(event.once) client.rest.once(event.name, execute);
else
client.rest.on(event.name, execute);
} else {
if(event.once) client.once(event.name, execute);
else
client.on(event.name, execute);
}

table.addRow(event.name, "Online")
})

return console.log(table.toString(), "\nLoaded Events")
}

module.exports = { loadEvents }
const config = require('dotenv').config()

const { Client, Events, GatewayIntentBits, SlashCommandBuilder, Partials, Collection } = require('discord.js');

const { Guilds, GuildMembers, GuildMessages } = GatewayIntentBits;

const { User, Message, GuildMember, ThreadMember } = Partials;

const { loadEvents } = require("./Handlers/eventHandler");

const client = new Client({
intents: [Guilds, GuildMembers, GuildMessages],
partials: [User, Message, GuildMember, ThreadMember]
});

client.events = new Collection();

loadEvents(client);


client
.login(process.env.DISCORD_TOKEN)
.then(() => {
console.log(`Successfully logged in`);
client.user.setActivity('Stwffer.it');
})
.catch((err) => console.log(err));
const config = require('dotenv').config()

const { Client, Events, GatewayIntentBits, SlashCommandBuilder, Partials, Collection } = require('discord.js');

const { Guilds, GuildMembers, GuildMessages } = GatewayIntentBits;

const { User, Message, GuildMember, ThreadMember } = Partials;

const { loadEvents } = require("./Handlers/eventHandler");

const client = new Client({
intents: [Guilds, GuildMembers, GuildMessages],
partials: [User, Message, GuildMember, ThreadMember]
});

client.events = new Collection();

loadEvents(client);


client
.login(process.env.DISCORD_TOKEN)
.then(() => {
console.log(`Successfully logged in`);
client.user.setActivity('Stwffer.it');
})
.catch((err) => console.log(err));
16 Replies
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
Marcus
MarcusOP17mo ago
This is my file structure
Marcus
MarcusOP17mo ago
anyone please?
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Marcus
MarcusOP17mo ago
I reworked everything now I got another problem
const config = require('dotenv').config()
const getLocalCommands = require('../../utils/getLocalCommands');

module.exports = async (client, interaction) => {

if (!interaction.isChatInputCommand()) return;

const localCommands = getLocalCommands();

try {

const commandObject = localCommands.find((cmd) => cmd.name === interaction.CommandName);

if (!commandObject) return;
if (commandObject.permissionsRequired?.length) {
for (const permission of commandObject.permissionsRequired) {
if(!interaction.member.permissions.has(permission)) {
interaction.reply({
content: `You don't have the right permission!`,
ephemeral: true,
});
break;
}

}

}

await commandObject.callback(client, interaction);

} catch (error) {
console.log(`There was an error running this command: ${error}`)
}
};
const config = require('dotenv').config()
const getLocalCommands = require('../../utils/getLocalCommands');

module.exports = async (client, interaction) => {

if (!interaction.isChatInputCommand()) return;

const localCommands = getLocalCommands();

try {

const commandObject = localCommands.find((cmd) => cmd.name === interaction.CommandName);

if (!commandObject) return;
if (commandObject.permissionsRequired?.length) {
for (const permission of commandObject.permissionsRequired) {
if(!interaction.member.permissions.has(permission)) {
interaction.reply({
content: `You don't have the right permission!`,
ephemeral: true,
});
break;
}

}

}

await commandObject.callback(client, interaction);

} catch (error) {
console.log(`There was an error running this command: ${error}`)
}
};
It's supposed to activate my slashcommand, but actually nothing happens when running the command ... O.o no errors or anything
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Marcus
MarcusOP17mo ago
it stops after the if (!interaction.isChatInputCommand()) I dont know why tho and how to fix
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Marcus
MarcusOP17mo ago
this is a complete new system nothing related with the upper
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Marcus
MarcusOP17mo ago
directly
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Marcus
MarcusOP17mo ago
yes
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Marcus
MarcusOP17mo ago
Yes can we maybe jump into a call or smth?
d.js docs
d.js docs17mo ago
The order of function parameters must match between definition and function call.
function execute(client, interaction) { ... };
execute(interaction, client);
function execute(client, interaction) { ... };
execute(interaction, client);
- mismatch! you pass an interaction where the client is expected - mismatch! you pass the client where an interaction is expected
Want results from more Discord servers?
Add your server