Some questions

Hello, I'm new Sapphire and I don't really know how to do the followings. Right now I have 2 issues: 1) I'm trying to understand how could i send an error message when for example someone tries to reuse the /apply command in a timeframe of 30 seconds, right now it will say "the application failed to respond", but i'd like to say something like "you're in a cooldown right now!" and 2) I'd like to understand how collectors really work, what I want to do is when someone answer a question it will send the next one immediately and at the end will send to the user every question+answer
Solution:
1) See https://sapphirejs.dev/docs/Guide/preconditions/reporting-precondition-failure 2) That's DiscordJS realm, not Sapphire. That said, if you're running a collector inside a slash command you should defer the reply first because otherwise you'll always exceed the 5 second timeout during which you have to reply as per Discord API restrictions. Furthermore, instead of using a message collector you should use slash command options or modals with text input fields, that too is DiscordJS realm (with a bit of https://sapphirejs.dev/docs/Guide/interaction-handlers/what-are-they in case of the latter)...
Jump to solution
20 Replies
Solution
Favna
Favna3mo ago
1) See https://sapphirejs.dev/docs/Guide/preconditions/reporting-precondition-failure 2) That's DiscordJS realm, not Sapphire. That said, if you're running a collector inside a slash command you should defer the reply first because otherwise you'll always exceed the 5 second timeout during which you have to reply as per Discord API restrictions. Furthermore, instead of using a message collector you should use slash command options or modals with text input fields, that too is DiscordJS realm (with a bit of https://sapphirejs.dev/docs/Guide/interaction-handlers/what-are-they in case of the latter)
davy
davy3mo ago
Also and to clear the command cache? i've seen a thread about this but for some reason i still have the old commands with the old descriptions and about the first, as i understand i have to create a precondition, in the example one it was the owner precondition, in my case would be like CooldownPrecondition or something like that?
Favna
Favna3mo ago
cooldown precondition is a built in precondition as described on https://sapphirejs.dev/docs/Guide/preconditions/command-cooldown
Favna
Favna3mo ago
Slash Commands GUI
Graphical User Interface to explore and edit your bot's slash commands!
Favna
Favna3mo ago
ideally you only need to do this during early development and once you got your groove going you're not constantly deleting commands anymore
davy
davy3mo ago
Also to understand, I have to create a Listener that listens to the ChatInput like in the report-precondition-failure page right?
Favna
Favna3mo ago
ChatInputCommandDenied, but other than that yes
davy
davy3mo ago
So just like copy paste as i understand
Favna
Favna3mo ago
pretty much
davy
davy3mo ago
but should i modify something in my apply command? because right now it still will say The application did not respond
Favna
Favna3mo ago
Discord API states that by default you need to reply within 3 seconds to an interaction, unless you defer a rely. 3 < 30, ergo yes it will say it didn't respond. see https://discordjs.guide/slash-commands/response-methods.html#deferred-responses for more info
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Favna
Favna3mo ago
(I said 5 before, I was wrong it's 3) basically when writing a bot, especially starting out, you'd do well to always know to reference: 1. Sapphire docs/guide: https://sapphirejs.dev 2. DiscordJS docs: https://discord.js.org 3. DiscordJS guide: https://discordjs.guide/ 4. Discord API docs/guide: https://discord.dev (not necessarily in that order)
davy
davy3mo ago
Yeah its the first time for me it's more like i don't know how to structure the command because i think its horrible to write everything in the command class
Favna
Favna3mo ago
nah that's pretty normal but dont forget your JS / NodeJS basics, you can always extract code to functions and import them. Just make sure to pass the right arguments and return the correct stuff
davy
davy3mo ago
so like i could create a func folder put there the application stuff and then import it in the command and just use that function?
Favna
Favna3mo ago
yes you're not the only user of sapphire, you can look at other bots for examples
Sapphire
Sapphire3mo ago
Discord Bots using @sapphire/framework v5.x - Gemboard ᴱ ᴰ - Skyra ᴱ ᴬ ᴰ - Dragonite ᴱ ᴰ - Archangel ᴱ ᴰ - Official Bot Examples ᴱ ᴰ ᴶˢ - KBot ᴱ ᴬ ᴰ v4.x - Radon ᴱ ᴬ - Sapphire Application Commands Examples ᴱ - Zeyr ᴰ ᴬ - Birthdayy ᴰ - RTByte ᴱ ᴬ Legend for the identifiers : Uses ESM (if not specified then uses CJS) : Advanced bot (if not specified it is a simple bot, or not graded) : Uses Docker in production ᴶˢ: Written in JavaScript. If not specified then the bot is written in TypeScript.
davy
davy3mo ago
Yeah this was the next thing i was going to ask, well, thanks for answering me so fast and if I need something else i can just reopen a new post right?
Favna
Favna3mo ago
yes
davy
davy3mo ago
thank you :)