Hello, i am trying to make a uptime checker thing. I'm currently just using a ready listener for test.
main.ts
import 'dotenv/config';import { SapphireClient } from '@sapphire/framework';import { GatewayIntentBits } from 'discord.js';// Loggingimport { Logger, ILogObj } from "tslog";const logger: Logger<ILogObj> = new Logger();const client = new SapphireClient({ intents: [ GatewayIntentBits.MessageContent, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ], loadMessageCommandListeners: true});const token: string | undefined = process.env.BOT_TOKEN;async function run() { if (!token) { logger.fatal("Token is empty"); return; } try { await client.login(token); logger.info("Client logged in successfully"); } catch (error) { logger.fatal("Failed to log in", error); }}run().catch((error) => { logger.fatal("Unexpected error occurred in run", error);});
import 'dotenv/config';import { SapphireClient } from '@sapphire/framework';import { GatewayIntentBits } from 'discord.js';// Loggingimport { Logger, ILogObj } from "tslog";const logger: Logger<ILogObj> = new Logger();const client = new SapphireClient({ intents: [ GatewayIntentBits.MessageContent, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ], loadMessageCommandListeners: true});const token: string | undefined = process.env.BOT_TOKEN;async function run() { if (!token) { logger.fatal("Token is empty"); return; } try { await client.login(token); logger.info("Client logged in successfully"); } catch (error) { logger.fatal("Failed to log in", error); }}run().catch((error) => { logger.fatal("Unexpected error occurred in run", error);});
ready.ts
import { Listener } from '@sapphire/framework';import type { Client, UserResolvable } from "discord.js";export class ReadyListener extends Listener { public constructor(context: Listener.LoaderContext, options: Listener.Options) { super(context, { ...options, once: true, event: 'ready' }); } public async run(client: Client) { const userID: UserResolvable = "snowflake-id"; try { const user = await client.users.fetch(userID); const presence = user.client.user.presence console.log("Sapphire status: " + presence.status) } catch (error) { console.error("Error fetching user:", error); } }}
import { Listener } from '@sapphire/framework';import type { Client, UserResolvable } from "discord.js";export class ReadyListener extends Listener { public constructor(context: Listener.LoaderContext, options: Listener.Options) { super(context, { ...options, once: true, event: 'ready' }); } public async run(client: Client) { const userID: UserResolvable = "snowflake-id"; try { const user = await client.users.fetch(userID); const presence = user.client.user.presence console.log("Sapphire status: " + presence.status) } catch (error) { console.error("Error fetching user:", error); } }}
I'm sure that my client is logging up and ready (line 30 in main.ts gets executed)
Solution
1. Which version of
@sapphire/framework
@sapphire/framework
are you using? 2. What's your file/folder structure? 3. Did you use the CLI to generate your bot? 4. What's your
main
main
(CJS) or
module
module
(ESM) property in
package.json
package.json
5. Are you using TypeScript? And if so, how are you compiling and running your code? That is to say, what are your build and startup scripts? - Did you remove your output folder and rebuild then try again? 6. Is your problem related to message commands? Did you add