Run bot without building to js and use ts-node or other alternatives instead.

Is there a way to achieve the title? Currently I need to build and then run the js file using the command:
npm run build && npm run start
npm run build && npm run start
Solution:
If you want to test the bot, then tsc-watch is good. Or you can remove typescript & code directly in js Or you can use bun runtime to start your typescript based bot directly (you will need to refactor your code so that it runs on bun)...
Jump to solution
10 Replies
Solution
MRDGH2821
MRDGH282113mo ago
If you want to test the bot, then tsc-watch is good. Or you can remove typescript & code directly in js Or you can use bun runtime to start your typescript based bot directly (you will need to refactor your code so that it runs on bun)
abe
abeOP13mo ago
I would prefer to use typescript and i don't really want to use another runtime
MRDGH2821
MRDGH282113mo ago
tsc-watch & tsup have an option called onSuccess <do something> So you can leverage that. Or create a new script in package.json:
{
"scripts": {
"dev": "npm run build && npm run start",
}
}
{
"scripts": {
"dev": "npm run build && npm run start",
}
}
MRDGH2821
MRDGH282113mo ago
GitHub
examples/examples/with-typescript-starter/package.json at main · sa...
Various examples of setting up your bot with the Sapphire Framework - sapphiredev/examples
Spinel
Spinel13mo 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 websocket 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 login 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.
disclosuure
disclosuure13mo ago
Slightly off topic but is there an equivalent to tsc-watch for swc?
KaydaFox
KaydaFox13mo ago
Install chokidar and add "-w" for watching
KaydaFox
KaydaFox13mo ago
@swc/cli – SWC
SWC is an extensible Rust-based platform for the next generation of fast developer tools. It's used by tools like Next.js, Parcel, and Deno, as well as companies like Vercel, ByteDance, Tencent, Shopify, and more.
disclosuure
disclosuure13mo ago
Thank you. I meant the way you can use --onSuccess, it doesn't seem to exist for swc without watching both src and dist with separate scripts.
KaydaFox
KaydaFox13mo ago
Ah my bad. Yeah I'm not sure if that exists
Want results from more Discord servers?
Add your server