Optimal way of developing with typescript

Hello! I've been using sapphire for some days now, and one thing that I'm trying to achieve is to not change anything in the source code of my bot when being done with my developing and deploying to production, or going back to developing after deploying. I may be completely wrong, but in the documentation, it says that sapphire needs the "main" property of the package.json to point to the main file of my bot. But the issue I'm personally having is that when developing in typescript, I point the "main" property to something like "src/index.ts", but before deploying to production, I manually change that to "dist/index.js". Is there a way to avoid manually changing the "main" property when developing->deploying?
Solution:
Tsc-watch config is included in sapphire's template bot. So You can use that instead...
M
MRDGH282141d ago
Although bun can directly run typescript files without transpilation/compilation to JS You have to keep the main to dist/index.js & compile/transpile the files to JS (often known as Build Step)
P
Pipexlul41d ago
Oh I see, I was trying to avoid the transpilation when developing (I was using ts-node-dev) I'll mark your answer as the solution in a bit in case someone else knows if any other way is possible
M
MRDGH282141d ago
There's a better way
S
Spinel41d ago
Tag suggestion for @Pipexlul: 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.
Solution
M
MRDGH282141d ago
Tsc-watch config is included in sapphire's template bot. So You can use that instead
P
Pipexlul41d ago
Thank you a lot. That solves my issue 100%
M
MRDGH282141d ago
GitHub
examples/examples at main · sapphiredev/examples
Various examples of setting up your bot with the Sapphire Framework - sapphiredev/examples
Want results from more Discord servers?
Add your server
More Posts
/test command doesn't work but /ping does?code: https://paste.ee/p/k2cXx please ping me when you respond! Thanks in advanceFailure Handling With Listeners.This is more a design/architecture question. Just need more input. So, a few of the commands I am commands doesnt workclient.commands = new Collection(); const commandFiles = fs.readdirSync('/root/eye/Eye/Eye/commandsRunning Async Code in PrecinditionsI didn’t see this in the docs. But, is it possible to run async code in preconditions? TLDR: I needButtons InteractionsHello fellows, I have some questions. I'm a developer with experience with jda-ktx and JDA, I'm notGetting Data from .env FileI created a new Sapphire app using the CLI. I am using swc. And, I want to ask how do access env varTesting and Sapphire/discord.jsHeya. I'm new to Sapphire and Discord, but not new to JavaScript or coding in general. I'd love som/twitchadd (name) (link)name = choice name link = choice valueplease helpwe need help with a non respondent monitor and we have tried unplugging and changing the cords PLEASHello ,I need some Help about listeners in sapphire frameworkany one have a working example of ("guildMemberAdd") , a bot that welcome user when they join the seTypescript error in @ApplyOptions```ts import { ApplyOptions } from '@sapphire/decorators'; import { Command } from '@sapphire/framewIs there events listing like discord.js does?Just like in the screenshot, discord.js has listed out all events . So where I can find the same fomaking a !help command. where do i get the commands from?im trying to make a help command since I've started learning about paginated messages, but where wouthis.error()Is there any way of using `this.error()` but not trigger `messageCommandDenied`? This is because on Throwing errors in commands/subcommandsJust curious if there is a way to throw an error in an application command/subcommand and have it haDynamic subcommand methodsHey, i am creating some subcommands that basically have the same runner method, but i would wanna knHow do i use "separators" command in sapphire?Hi! Im new at sapphire/framework, i was reading the docs and seeing there is a `separators` options Limit command to specified roles?I honestly haven't done this in a while (not since pre-application commands) and am new to using SapHow to reference client in main file?I am trying to get `<Client>.users` from the index.ts but I am unsure as to how I would get around tList registered commands and listenersHi, i love working with sapphire it's amazing. I'm just wondering is there a way to obtain some sort