#Hi! I'm new in Sapphire!
1 messages · Page 1 of 1 (latest)
Check out our getting started guide: https://sapphirejs.dev, if you're still having difficulty please be more verbose.
- Which version of
@sapphire/frameworkare you using? - What's your file/folder structure?
- Did you use the CLI to generate your bot?
- What's your
main(CJS) ormodule(ESM) property inpackage.json - 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?
- Is your problem related to message commands? Did you add
loadMessageCommandListenersto yourSapphireClientoptions
Remember that if you are new to @sapphire/framework it is important that you read the user guide.
- Recent Version
- Hmm, no
- "main": "src/index.js",
- Yes, yes, yes, yes
- Hmmm, yes
This really doesnt say much. The version is in your package.json, please share it. Are you by chance also new to NodeJS or maybe even software development as a whole?
Despite your answer to 5 you have both JS and TS files. Also only the first and last questions of 5 are yes/no question,. not all 4. Following from question 4 you're also NOT using typescript, because you say you're loading index.js. You need to decide between the one or the other and currently you have a mix of the two. Lets start there.
{
"name": "Bot",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "node .",
"build": "tsc",
"dev": "ts-node src/bot.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@sapphire/framework": "^5.0.4",
"discord.js": "^14.14.1"
},
"devDependencies": {
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
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.
for starters
Yes, im new
Before you make a Discord Bot, you should have a good understanding of JavaScript. This means you should have a basic understanding of the following topics:
- Read and understand docs
- Debug code
- Syntax
- NodeJS module system
If you aren't sure that your understanding of JavaScript is truly good enough to make a bot, you should try to continue learning first. Here are good resources to learn both Javascript and NodeJS:
Codecademy: https://www.codecademy.com/learn/javascript
Udemy: https://www.udemy.com/javascript-essentials/
Eloquent JavaScript, free book: http://eloquentjavascript.net/
You-Dont-Know-JS: https://github.com/getify/You-Dont-Know-JS
JavaScript Garden: https://bonsaiden.github.io/JavaScript-Garden/
JavaScript reference/docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
Nodeschool: https://nodeschool.io/
Pluralsight: https://www.codeschool.com/courses/real-time-web-with-node-js
Before you ask a question, you should ask these yourself:
- Is this question related to JavaScript, or the library I am using?
- If it is the library you are using, go to the proper server. You would get better answers there.
- Have I tried to google and/or check StackOverflow?
- Double-check that you can't find anywhere that can lead you to a solution online.
- Have I tried to look on MDN or the library documentation?
- You should always check documentation to make sure you aren't missing any details.
- Does my question make enough sense so that people can understand it, and do they understand what I am trying to accomplish?
- If no, revise your question. Give as much detail as possible. Include any error or code output that can help us help you.
- Am I aware of what I am doing, and not just mindlessly copying and pasting?
- If you are just copying and pasting code from a guide, you are not going to be able to solve anything. Make sure you understand the code you are writing.
bunch of reading I know but you'll be better for it
Simply diving headfirst into the unknown isn't the best of ideas
I started learning typescript, however, I have questions related to package.
I don't speak English, so using a translator sometimes takes it out of context in docs
Ah yes that is a big hurdle when programming. You'll get there eventually but you'll have a hard uphill battle to overcome.
For now use @sapphire/cli to generate a starter template (https://www.sapphirejs.dev/docs/Guide/CLI/getting-started)
I just wanted to know how do I load a command from a folder to work
The guide will teach you or the setup will done for you when generating from a template.