Jimsalad
Jimsalad
SIASapphire - Imagine a framework
Created by Jimsalad on 8/7/2024 in #sapphire-support
TS App does not attach event listeners once complied, works in dev
Note this also needs to be relevant to where you're booting from, you can't just specify a folder path and it works it out.
10 replies
SIASapphire - Imagine a framework
Created by Jimsalad on 8/7/2024 in #sapphire-support
TS App does not attach event listeners once complied, works in dev
For anyone that stumbles upon this in future with similar symptoms (app booting, bot is registered online in discord but events not picked up) my solution was to update package.json's main parameter to an appropriate value against the compiled JS entrypoint - in my case dist/index.js.
10 replies
SIASapphire - Imagine a framework
Created by Jimsalad on 8/7/2024 in #sapphire-support
TS App does not attach event listeners once complied, works in dev
As always, typing the problem out helps you solve it 😅 Thanks for being a rubber duck...
10 replies
SIASapphire - Imagine a framework
Created by Jimsalad on 8/7/2024 in #sapphire-support
TS App does not attach event listeners once complied, works in dev
Finally, index.ts looks like this and is the root of my application
import "dotenv/config";
import { SapphireClient, LogLevel } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";
import logger from "./lib/logger";
import server from "./server";

const httpPort = 8080;

if (typeof process.env.TOKEN !== "string" || process.env.TOKEN === "") {
throw new Error("TOKEN secret not set");
}

const client = new SapphireClient({
logger: { level: LogLevel.Debug },
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
],
loadMessageCommandListeners: true,
});

client.login(process.env.TOKEN);
logger.info("Discord client logged in");

server.listen(httpPort, () => {
logger.info(`App listening on port ${httpPort}`);
});
import "dotenv/config";
import { SapphireClient, LogLevel } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";
import logger from "./lib/logger";
import server from "./server";

const httpPort = 8080;

if (typeof process.env.TOKEN !== "string" || process.env.TOKEN === "") {
throw new Error("TOKEN secret not set");
}

const client = new SapphireClient({
logger: { level: LogLevel.Debug },
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
],
loadMessageCommandListeners: true,
});

client.login(process.env.TOKEN);
logger.info("Discord client logged in");

server.listen(httpPort, () => {
logger.info(`App listening on port ${httpPort}`);
});
10 replies
SIASapphire - Imagine a framework
Created by Jimsalad on 8/7/2024 in #sapphire-support
TS App does not attach event listeners once complied, works in dev
Compiled app is started via a node ./index.js command relative to the /dist folder. Dist folder looks like the below once built via Dockerfile
/dist # ls -a
. commands index.js listeners package-lock.json server.js
.. errors lib node_modules package.json
/dist # ls -a
. commands index.js listeners package-lock.json server.js
.. errors lib node_modules package.json
10 replies
SIASapphire - Imagine a framework
Created by Jimsalad on 8/7/2024 in #sapphire-support
TS App does not attach event listeners once complied, works in dev
My tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"baseUrl": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
}
}
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"baseUrl": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
}
}
10 replies
SIASapphire - Imagine a framework
Created by Jimsalad on 8/7/2024 in #sapphire-support
TS App does not attach event listeners once complied, works in dev
My package.json dependencies and scripts:
"dependencies": {
"@sapphire/framework": "^5.2.1",
"@types/express": "^4.17.21",
"@types/node": "^22.1.0",
"debug": "^4.3.6",
"discord.js": "^14.15.2",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"mysql2": "^3.11.0",
"ts-node": "^10.9.2",
"typescript": "5.4.5",
"winston": "^3.13.1"
},
"scripts": {
"build": "tsc -p .",
"start:dev": "nodemon -L ./src/index.ts"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"husky": "^9.1.4",
"nodemon": "^3.1.4"
}
"dependencies": {
"@sapphire/framework": "^5.2.1",
"@types/express": "^4.17.21",
"@types/node": "^22.1.0",
"debug": "^4.3.6",
"discord.js": "^14.15.2",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"mysql2": "^3.11.0",
"ts-node": "^10.9.2",
"typescript": "5.4.5",
"winston": "^3.13.1"
},
"scripts": {
"build": "tsc -p .",
"start:dev": "nodemon -L ./src/index.ts"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"husky": "^9.1.4",
"nodemon": "^3.1.4"
}
10 replies