Difference with dev and prod > The application now has 0 global commands

Not sure what I'm missing here. When I run my dev command nodemon src/Bot.ts - everything works as expected, the bot is online and responsive, with 4 global commands. When I run my build command tsc - the build is successful Now, if I try to run the built files, with node dist/Bot.js the bot is online, but it registers 0 global commands, and none of my listeners or commands of any type respond. I'm baffled and not sure what I'm missing here. I've tried clearing the dist folder, the resulting js files do have the bundled content and everything looks as expected. tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es2022",
"rootDir": "src",
"outDir": "dist",
"lib": ["ESNext", "ESNext.Array", "ESNext.AsyncIterable", "ESNext.Intl", "ES2015.Symbol", "DOM"],
"sourceMap": true,
"inlineSources": true,
"incremental": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es2022",
"rootDir": "src",
"outDir": "dist",
"lib": ["ESNext", "ESNext.Array", "ESNext.AsyncIterable", "ESNext.Intl", "ES2015.Symbol", "DOM"],
"sourceMap": true,
"inlineSources": true,
"incremental": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
Solution:
See the first big red block at the getting started guide https://sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire
Sapphire Framework
Getting started with Sapphire | Sapphire
To install Sapphire, you need to install both discord.js and
Jump to solution
13 Replies
Sapphire
Sapphire2mo ago
1. Which version of @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 (CJS) or module (ESM) property in 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 loadMessageCommandListeners to your SapphireClient options Remember that if you are new to @sapphire/framework it is important that you read the user guide.
Favna
Favna2mo ago
2 and 4
Bejasc
BejascOP2mo ago
Hey fav, thanks for taking a look 👋
Bejasc
BejascOP2mo ago
No description
Bejasc
BejascOP2mo ago
package.json
{
"name": "@australis/bot",
"version": "1.0.0",
"description": "SC-Australis Bot",
"author": "Bejasc (https://github.com/bejasc)",
"main": "src/Bot.ts",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"start": "node dist/Bot.js",
"dev": "nodemon src/Bot.ts",
"format": "prettier --write \"src/**/*.ts\""
},
"dependencies": {
"@australis/types": "workspace:^",
"@bejasc/helpers": "workspace:^",
"@bejasc/logger": "workspace:^",
"@sapphire/decorators": "^6.1.0",
"@sapphire/framework": "^5.2.1",
"@sapphire/plugin-subcommands": "^7.0.0",
"axios": "^1.2.1",
"discord.js": "^14.16.3",
"tsc-watch": "^6.2.0",
"typescript": "^5.6.2"
},
"installConfig": {
"hoistingLimits": "workspaces"
}
}
{
"name": "@australis/bot",
"version": "1.0.0",
"description": "SC-Australis Bot",
"author": "Bejasc (https://github.com/bejasc)",
"main": "src/Bot.ts",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"start": "node dist/Bot.js",
"dev": "nodemon src/Bot.ts",
"format": "prettier --write \"src/**/*.ts\""
},
"dependencies": {
"@australis/types": "workspace:^",
"@bejasc/helpers": "workspace:^",
"@bejasc/logger": "workspace:^",
"@sapphire/decorators": "^6.1.0",
"@sapphire/framework": "^5.2.1",
"@sapphire/plugin-subcommands": "^7.0.0",
"axios": "^1.2.1",
"discord.js": "^14.16.3",
"tsc-watch": "^6.2.0",
"typescript": "^5.6.2"
},
"installConfig": {
"hoistingLimits": "workspaces"
}
}
4 - nothing set directly for module - but entire package.json listed above
Favna
Favna2mo ago
You have set it, 5th field
Solution
Favna
Favna2mo ago
See the first big red block at the getting started guide https://sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire
Sapphire Framework
Getting started with Sapphire | Sapphire
To install Sapphire, you need to install both discord.js and
Bejasc
BejascOP2mo ago
hah! changed it to dist/Bot.js - fixed it. I missed that 😓 thankyou mate - I compared it to my other bot that was running in prod and then it jumped at me - I must've scaffolded this package from something different
Favna
Favna2mo ago
Yeah but now nodemon src Bot.ts doesn't work however presumably nodemon uses tsnode in the background so then:
Sapphire
Sapphire2mo ago
TL;DR: Do not use ts-node, use tsc-watch instead. We very strongly discourage using ts-node because it was never meant to be used for bots. ts-node is designed for REPL purposes. That's short for Read Eval Print Loop. Which means to read some code, dump it in an eval() statement, print the result, and loop. A discord bot is not that. A Discord bot sets up a permanent web socket connection to the Discord server and connects to the rest gateway. There is read yes, but no eval, no print, and no loop. So what should you use instead? The most ideal way is to just use the watch flag of tsc (tsc --watch) and run node dist/index.js to run your bot, then cancel that process and restart it when you have changes that require restarting. You would open 2 terminal tabs, 1 in which you run tsc --watch and another in which you run the bot. This is, in particular, the most ideal way, because Discord has a limit to the amount of times you can log in with your bot, or register commands, per day. Constantly logging in over and over again due to an auto-restarting process will get you close to that limit very quickly and once you exceed it, your development will be halted entirely for the current day. However, this can be quite tedious so a great package to use instead is tsc-watch.
Bejasc
BejascOP2mo ago
I may not even need to use nodemon - scaffolded from something else, my other prod package is using this as it's dev command "dev": "tsc-watch --onSuccess \"node --enable-source-maps ./dist/Bot.js\" ", Which has worked well I'll likely migrate over to that and refer to your above message
Favna
Favna2mo ago
It never hurts to copy paste
Bejasc
BejascOP2mo ago
thanks for letting me bounce off you, appreciate the quick response 🙏

Did you find this page helpful?