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:Jump to 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)...
20 Replies
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)
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?
cooldown precondition is a built in precondition as described on https://sapphirejs.dev/docs/Guide/preconditions/command-cooldown
use the discordjs methods https://discord.js.org/docs/packages/discord.js/14.14.1/ApplicationCommandManager:Class#set or a site such as https://slash-commands-gui.androz2091.fr
Slash Commands GUI
Graphical User Interface to explore and edit your bot's slash commands!
ideally you only need to do this during early development and once you got your groove going you're not constantly deleting commands anymore
Also to understand, I have to create a Listener that listens to the ChatInput like in the report-precondition-failure page right?
ChatInputCommandDenied, but other than that yes
So just like copy paste as i understand
pretty much
but should i modify something in my apply command? because right now it still will say The application did not respond
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.
(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)
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
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
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?
yes
you're not the only user of sapphire, you can look at other bots for examples
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.
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?
yes
thank you :)