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
Solution:Jump to 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
13 Replies
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.2 and 4
Hey fav, thanks for taking a look 👋
package.json
4 - nothing set directly for module - but entire package.json listed above
You have set it, 5th field
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
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 differentYeah but now nodemon src Bot.ts doesn't work however presumably nodemon uses tsnode in the background so then:
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
.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 messageIt never hurts to copy paste
thanks for letting me bounce off you, appreciate the quick response 🙏