#Discord.js client.on('ready') imported from another file not working

7 messages · Page 1 of 1 (latest)

foggy linden
#
//Client.ts
export class ExtendedClient extends Client {
    commands: Collection<string, CommandType> = new Collection();

    constructor() {
        super({ intents: 32767 });
    }

    start(){
        this.RegisterModules()
        this.login(process.env.BotToken)
    }

    async ImportFile(FilePath: string){
        return (await import(FilePath))?.default;
    }

    async RegisterCommands( {Commands, GuildId: GuildID}: RegisterCommandOptions){
        if (GuildID){
            this.guilds.cache.get(GuildID)?.commands.set(Commands);
            console.log(`Registered ${Commands.length} commands in guild ${GuildID}`);
            
        }else{
            this.application?.commands.set(Commands);
            console.log(`Registered ${Commands.length} global commands`);
        }
    }


    async RegisterModules(){
        // Commands
        const slashCommands: ApplicationCommandDataResolvable[] = [];
        const commandFiles = await globPromise(
            `${__dirname}/../Commands/*/*{.ts,.js}`
        );
        commandFiles.forEach(async (filePath) => {
            const command: CommandType = await this.ImportFile(filePath);
            if (!command.name) return;
            console.log(command);

            this.commands.set(command.name, command);
            slashCommands.push(command);
        });

        this.on("ready", () => {
            this.RegisterCommands({
                Commands: slashCommands,
                GuildId: process.env.GuildId
            });
            server.CheckSentInvoices()
        });

        // Events
        const EventFiles = await globPromise(
            `${__dirname}/../events/*{.ts,.js}`
        );
        EventFiles.forEach(async (filePath) => {
            const event: Event<keyof ClientEvents> = await this.ImportFile(
                filePath
            );
            this.on(event.event, event.run);
        });
    }
}
fierce raft
#

• 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.

foggy linden
#
//ready.ts
import { Event } from "../structures/Event";

export default new Event('ready', () => {
    console.log(`Bot is alive!`);
});

this is the console.log() I'm waiting for

also, slash commands don't work for some reason...

I tried running the bot on Windows and it runs perfect... it's only when using Ubuntu Linux that it doesn't work

olive elbow
barren warrenBOT
#

Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.

client
    .on("debug", console.log)
    .on("warn", console.log)

• Note: if you initialize your Client as bot or other identifiers you need to use these instead of client
• If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin

foggy linden
# olive elbow So your bot doesn’t login on Linux. Debug why that is

Did that

Here's the log:

    URL: wss://gateway.discord.gg
    Recommended Shards: 1
[WS => Manager] Session Limit Information
    Total: 1000
    Remaining: 975
[WS => Manager] Spawning shards: 0
[WS => Shard 0] [CONNECT]
    Gateway    : wss://gateway.discord.gg/
    Version    : 10
    Encoding   : json
    Compression: none
[WS => Shard 0] Setting a HELLO timeout for 20s.
[WS => Shard 0] [CONNECTED] Took 397ms
[WS => Shard 0] Clearing the HELLO timeout.
[WS => Shard 0] Setting a heartbeat interval for 41250ms.
[WS => Shard 0] [IDENTIFY] Shard 0/1 with intents: 32767
[WS => Shard 0] [READY] Session 1a30644c7d54dec8f4b8be59fca0bdf4 | Resume url wss://gateway-us-east1-b.discord.gg.
[WS => Shard 0] [ReadyHeartbeat] Sending a heartbeat.
[WS => Shard 0] Shard received all its guilds. Marking as fully ready.```

still, client.on("ready") doesn't work