Help

I wanted to make an eventHendler using a table. I did everything according to the guide on YouTube, but it doesn't work, there are no errors. index.js
const { Client, GatewayIntentBits, Partials, Collection } = require("discord.js");
const { Guilds, GuildMembers, GuildMessages } = GatewayIntentBits;
const { User, Message, GuildMember, ThreadMember } = Partials;

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

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

client.config = require("./config.json");
client.events = new Collection();

loadEvents(client);

client
.login(client.config.token)
.then( () => {
console.log(`client logged is as ${client.user.username}`);
client.user.setActivity(`with ${client.guilds.cache.size} guilds(s)`);
})
.catch((err) => console.log(err));
const { Client, GatewayIntentBits, Partials, Collection } = require("discord.js");
const { Guilds, GuildMembers, GuildMessages } = GatewayIntentBits;
const { User, Message, GuildMember, ThreadMember } = Partials;

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

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

client.config = require("./config.json");
client.events = new Collection();

loadEvents(client);

client
.login(client.config.token)
.then( () => {
console.log(`client logged is as ${client.user.username}`);
client.user.setActivity(`with ${client.guilds.cache.size} guilds(s)`);
})
.catch((err) => console.log(err));
fileLoader.js
const { glob } = require("glob");
const { promisify } = require("util");
const proGlob = promisify(glob);

async function loadFiles(dirName){
const Files = await proGlob(`${process.cwd().replace(/\\/g, "/")}/${dirName}/**/*.js`);
Files.forEach((file) => delete require.cache[require.resolve(file)]);
return Files;
}

module.exports = { loadFiles }
const { glob } = require("glob");
const { promisify } = require("util");
const proGlob = promisify(glob);

async function loadFiles(dirName){
const Files = await proGlob(`${process.cwd().replace(/\\/g, "/")}/${dirName}/**/*.js`);
Files.forEach((file) => delete require.cache[require.resolve(file)]);
return Files;
}

module.exports = { loadFiles }
7 Replies
d.js toolkit
d.js toolkit16mo 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!
Обкуренный
eventHandler.js
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, "🟩")
})

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

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, "🟩")
})

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

module.exports = { loadEvents };
Events \ Client \ ready.js
module.exports = {
name: "ready",
once: true,
execute() {
console.log("The client is now ready.")
}
}
module.exports = {
name: "ready",
once: true,
execute() {
console.log("The client is now ready.")
}
}
treble/luna
treble/luna16mo ago
Follow the guide instead of a yt tutorial, they get outdated really quickly
Обкуренный
I understand that, now I can't figure out what's wrong
Cae
Cae16mo ago
If that is lyxcode eventhandler look for latest video where he posted the updated version..
Обкуренный
Yes, thanks, but now commandsHandler is not working
Cae
Cae16mo ago
Why dont you ask on his discord?
Want results from more Discord servers?
Add your server