#why doesn't work?

1 messages · Page 1 of 1 (latest)

spark silo
#

why doesn't work?

const event: BaseEvent = {
    name: 'ready',
    once: false,
    async execute(client: Client) {
        await client.logger.init(client);
        client.user.setActivity(`discord.js`, { type: ActivityType.Watching });
   }
}

export default event;
#

handler event

export default async function init(client: Client) {
    client.logger.send(`[HANDLER/EVENTS] Hanfler event loaded.`);
    await walk(client, './dist/events/');
}

async function walk(client: Client, dir: string) {
    if (Array.isArray(dir)) return;
    if (!(await lstat(dir)).isDirectory() ) {
        const event: BaseEvent = (await import(`../${dir}`.replace('/dist', '')))?.default;
        if (event.once) {
            client.once(event.name, (...args) => event.execute(client, ...args));
        } else {
            client.on(event.name, (...args) => event.execute(client, ...args));
        }
        client.logger.send(`[HANDLER/EVENTS] Listener "${event.name}" loaded.`);
        return;
    }
    for(let file of (await readdir(dir))) {
        await walk(client, join(dir, file));
    }
    return;
}
thorn zinc
#

in what way does it not work?
do you have any errors?

spark silo
#

ready event is loaded, but not working

thorn zinc
#

I'll just assume by "not working" you mean that it doesn't execute at all

#

does this walk function get called at all?
where do you even log in?

spark silo
# thorn zinc does this walk function get called at all? where do you even log in?

other events work successfully

I login like this:

client.login(process.env.TOKEN)
     .then(async() => {
         await client.logger.init(client);
         client.logger.send(`[INDEX] Bot initialization`);

         (await import(`./handlers/events`)).default(client).catch(client.logger.error);
         (await import(`./handlers/commands`)).default(client).catch(client.logger.error);

         client.on('error', client.logger.error)
         client.on('warn', client.logger.send)
         process.on('uncaughtException', client.logger.error);
         process.on('unhandledRejection', client.logger.error);
     });
thorn zinc
#

is client.logger.init the above init function?

#

the one that calls walk?

thorn zinc
#

then you should consider listening to events before logging in
the ready event is emitting before you listen to it

spark silo
#

walk is in the event handler

thorn zinc
#

ok