Sapphire - Imagine a framework

SIA

Sapphire - Imagine a framework

Welcome to the Sapphire Discord server! The next-gen object-oriented Discord.js bot framework can be found here.

Join

sapphire-support

discordjs-support

old-sapphire-support

old-discordjs-support

old-application-commands-and-interactions

Error please help

```ts import { ApplyOptions } from '@sapphire/decorators'; import { Command, RegisterBehavior } from '@sapphire/framework'; import { send } from '@sapphire/plugin-editable-commands'; import { Subcommand } from '@sapphire/plugin-subcommands';...

Subcommand Aliases

How can I add aliases to subcommands? Is it not possible?

Are command instance recreated every time someone use the associate slash command ?

Hello I was wondering : imagine i have a simple ping slash command who return "pong". Will sapphire recreate an instance of my Ping class (who register the command) every time do /ping or not ?...
Solution:
From my understanding; No, they're created at load time and then just saved to the command store and ran through that

Promise error sometimes on load - sapphire.js framework

Hey, Whenever I am starting my bot within a docker environment, I am getting this error sometimes; ```2024-04-22 12:04:51 - DEBUG - ApplicationCommandRegistries(BulkOverwrite) Overwriting global application commands, now at 0 commands...

Caching Problems

Hey, i have some problems with caching, on discord.js they sad All Guilds are cached if you have the intent, and the client is ready. While using intents like GuildMembers & Guilds. i dont know if it fits into this forum, i tough because sapphire initates the listeners.... ...

Registering Context Commands

Hello I want to register a context command with this code : ```js...

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)...

Sapphire command not recognized

I'm trying to install and use sapphire CLI but doesn't matter if I use NPM or Yarn 4.1.1, when I install it and try and run sapphire -v I get this back
Solution:
You can only call it that way if installed globally, which yarn berry (V2+) doesn't even do. Run it with yarn sapphire / yarn dlx sapphire instead. Or install it globally, how depends on your package manager (GIYF)
No description

API Plugin Prefix

Hey all, for some reason my prefix isn't applying on the data paths This is my env file: ``` API...
Solution:
disregard, it seems that it was due to something local, I reinstalled all the node_modules and the prefix worked correctly.

Task was not found | plugin-scheduled-tasks

👋🏿 I'm getting "[ScheduledTaskPlugin] There was no task found for "task_name"" error for all my scheduled tasks. Sometimes they run successfully but mostly they giving me this error. There is the code of how i'm declaring task: ```ts import { ApplyOptions } from "@sapphire/decorators"...
Solution:
you should use a different logical redis database for every bot then

Can't load subcommand

Hello, i'm trying to update to the latest djs and sapphire versions (from djs v13 and sapphire v3) and I have this structure for a subcommand where I have a file for each subcommand and a index where I declare and import them, before updating sapphire it searched all the files in the folder until it found the index, now it seems it only checks the first file (add) and doesn't load the subcommand correctly. Is there any way to fix this without having to change the structure and declare all the subcommands in one file? Error: ```Error when loading '/var/home/vicente/i/AnnounceIt/dist/src/commands/announcements/add.js': Error [EMPTY_MODULE]: A compatible class export was not found. [/var/home/vicente/i/AnnounceIt/dist/src/commands/announcements/add.js] at _LoaderStrategy.load (file:///var/home/vicente/i/AnnounceIt/node_modules/.pnpm/@[email protected]/node_modules/@sapphire/pieces/dist/esm/lib/strategies/LoaderStrategy.mjs:63:13)...
Solution:
That does not follow the structure for the command nor subcommand loader of sapphire or plugin-subcommands. If you want your subcommnands to be their own files with plugin-subcommands then 1. define them in the root command 2. import functions from other files 3. make sure those files start with a _ symbol (i.e. _add.ts) so sapphire skips them when loading 3. call those functions in the appropiate methods...
No description

multiplie registered handlers

Hi, is it better to split for example the button interactions for different buttons to different files? Or does it have any complications with the general performance? e.g. if i put everything in one file and fire functions to other files is that better? or does that make no difference...
Solution:
Makes no difference

TypeScript Check

Hey. The code works but I am curious if there is any way to do a better coding job like cleaniness etc. Thanks in advance! ```ts // © Sympact06 ...

Variable parameter type based on the previous variable

I want to add a 'parametric' set subcommand to one of my commands For that command the values can be user, role or a string. Can I somehow change the option type (for example use addRoleOption instead of addStringOption) based on the value of the type option? ```...
Solution:
I think this is possible if you use Auto complete If I'm correct, Autocomplete interaction should be able to give you values of previously filled parameters, which you can use to dynamically present values...

create a command that has spaces as one arg

for example, i would want a command with multiple spaces for each arg, such as !command <argwithspaces1> <argwithspaces2>, or even using seperators like | i just dont know where to start or if its even possible at all ( i tried using args.repeat and args.nextMaybe but that didnt work at all )...

Share sapphire stuff with multiple bots & possible monorepo setup

The question is what the better way to share sapphire stuff like utilities, handlers, commands folders with multiple bots? I need to have different bots for each category for example: economy, moderation, tickets, events, bots. Right now my project structure looks like this: ``` - bots - config...

Splitting Subcommand functions to multiple files

I have a command that has quite a few subcommands. I was wondering if there was any way to directly place a function in the messageRun chatInputRun entries so I could split the Subcommands into their own files/classes as the main command file is roughly 2.5k lines at the moment. I know I could just have each method inside of the class then call the other classes/files inside of it (which is what I'm currently doing), just wanted to see if there was a cleaner way. Is this possible?...
Solution:
You can use https://github.com/sawa-ko/neko-plugins/tree/main/packages/subcommands-advanced, it is not supported in the default plugin.

Commands and listeners

I've been reading the documentation for an hour and I don't really understand how the commands and listeners work. Is it possible for me to be sent the basis of a slash command and a listener that I can use?

Create a catch-all command to respond to any message?

I am working with AI, and so will actually likely only need a single command for the foreseeable future but I wanted to leave room for growth. What I actually want now is the ability to @mention the bot with a query: @bot translate x to y. The Command class from what I gather will only trigger based on the name and the aliases? Makes sense, just wondering if there is a way to maybe fall-back if the bot is pinged and does not match a command, could there be a "default" command? edit:...

Working with Emoji's on SelectMenu Options

Hi iam trying to set an emoji to a StringSelectMenu but i doesnt show the emoji itself. ```ts const selectMenu = new StringSelectMenuBuilder(); selectMenu.setCustomId("ticket:guild:select"); selectMenu.setPlaceholder(":arrow~2: Select a server to create a new ticket");...
No description