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

How 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 at Command my question is, how do i use the separators command option and how to get the key from it?
Solution:
You only customize the separators option if you have a very specific niche use case for customizing it. It is part of Options and defaults to one of = or :. If you want to know the current value (which will be ['=', ':'] by default) you can use this.options.separators

Limit command to specified roles?

I honestly haven't done this in a while (not since pre-application commands) and am new to using Sapphire. Looking to restrict a command to only be visible/usable by the server's owner and any roles they define. How is this best handled with Sapphire and application commands? The bot in question has a database to store roles if that's needed. Using TypeScript, here's a basic command I wrote that I want to restrict as described: ```ts // commands/example.ts...
Solution:
You'll have to write and handle your own precondition https://sapphirejs.dev/docs/Guide/preconditions/what-are-preconditions

How 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 to doing that..
Solution:
if youre using sapphire, you can do this.container.client or import the container from the framework and then container.client

List registered commands and listeners

Hi, i love working with sapphire it's amazing. I'm just wondering is there a way to obtain some sort of array or map of registered/loaded commands and listeners ? Appreciate sincerely all the answers...
Solution:
There are several ways to get the list of all commands, depending on the context of your current code. The following are the different methods: Inside another command:
this.store // Store<Command> extends Collection<Command> extends Map<Command>
this.store // Store<Command> extends Collection<Command> extends Map<Command>
...

Cannot find module

Anyone know what I need to install? (Ubuntu 22, image attached)
Solution:
https://github.com/nodejs/node-gyp#on-linux though sudo apt install build-essential should be the command you need...
No description

Module augmentation does not work

I recently updated my project with the latest versions of typescript and @sapphire/framework, and then I run into the problem that augmenting typing no longer works. I thought the problem would be pnpm, I even tried with the .npmrc configuration file "shamefully-hoist=true" but I'm still trying with yarn and the same thing happens, I don't know what to do. These are the versions I am using and my tsconfig file....
Solution:
normally module augments should work just fine if everything is done right though. The last time I had difficulties was when I had incorrectly published some package (i think it was pieces) where it was missing some files in dist. Maybe check that out for your own packages? Check the files array and check the dist?
No description

Conflicting types

I use the latest version of djs (14.14.1) and it seems like it has different types for taking the result from parsing.
Solution:
anyway if I write the code like this then it works fine: ```ts import { ApplyOptions } from '@sapphire/decorators'; import { Awaitable, InteractionHandler, InteractionHandlerTypes, Option } from '@sapphire/framework'; import { AutocompleteInteraction, type ApplicationCommandOptionChoiceData } from 'discord.js';...
No description

new to sapphirejs and discord bot overhaul

hi , i'm a new learner to make discord bot , i've gone a bit trought the basic of discordjs , was able to make work slash command , i switch to sapphirejs from a friend recommandation , but i didnt find how do we manage to send our command to discord api, i would love some direction help its been like 2day i'm learning to make discord bot , still on the basics of doing !ping command , slash command with multiple approach , done js / ts and now trying with sapphire...

Dump and load cached messages.

I'm not the one that usually works with the Discord Bot in our system, but I usually learn somethings. I know the Client keeps a cache of messages and such, ultimately I want to be able to get who deleted a message and why, is there a way to access the cache of messages directly, since Partials don't let me see anything from the onDeletedMessage....
Solution:
if you only want to get who deleted a message, the way i do it in bots i have for some servers is by fetching audit logs and comparing the author and stuff

How do interaction handlers pair up with commands

Hello! I'm trying to develop a little discord bot and I loved how complete the sapphire framework is. I've come across the interaction handlers section and tried to implement a command using a Select Menu one. The thing is, to trigger an interaction handler I first need to "make" the interaction through a command (like displaying a button). Let's say the command has a name param, how can I give the interaction-handler that information? Am I not using the right tool for what I'm trying to do?

Implement paginator , selection

so I want to have like a menu where you can pick several buttons and each button will show several options but each option should also have a paginato, what's the best class for this?
Solution:
I do something similar in my bot, I could not find a prebuilt class that handles that. Paginated Message would work but it’s not designed for that kind of functionality specifically so you’d have to override it. I use interaction handlers to do it in mine and it works really well. https://sapphirejs.dev/docs/Guide/interaction-handlers/what-are-they...

Any way to register a database client to the application command

Let's take this example: ```ts import { Command } from "@sapphire/framework"; ...

Using Paths w/ TypeScript

I'm trying to use TypeScripts Paths to make it easier and cleaner to import modules, although I always get: Cannot find package '@modules/mongodb' imported from C:\ExampleDirectory I've tried using node -r tsconfig-paths/register ., but that doesn't work and it still shows the same error above. ...
Solution:
Turns out that compiling it then running it with tsx works perfectly fine ```json "main": "dist/index.js", "type": "module", "scripts": {...

Select Menu Listener Fails To Register

Hello, I'm trying to implement a Select Menu Listener and get an error that a compatible class export cannot be found. I've copy-pasted the code exactly from the framework documentation/example and still receive the error. ...
Solution:
Nvm! I see it should be it's own folder, as mentioned in the forum post here: https://ptb.discord.com/channels/737141877803057244/1200406268435759176/1200407647694884965

Argument examples

Are there any examples for duration arguments available? I'm struggling with duration arguments for punishments and am looking for something that would accept either a "permanent" string or a duration with the type of a string, e.g 1h, 30d, 1m Iirc there was a plugin for this but I can't remember what the name is or where to find it....
Solution:

Message commands not working

When I run, nothing happens. No errors, no bot response. Here's the code: https://github.com/Bolaside/CrBn...
Solution:
Nevermind, I forgot to set loadMessageCommandListeners to true, silly me

Issue with @sapphire/plugin-api

Hello, I have installed @sapphire/plugin-api using the following command: ``` npm i @sapphire/plugin-api...
Solution:
Try setting your module (and moduleResolution) to node16. They are the modern options for module stuff. Alternatively you can install and extend @sapphire/ts-config which will cover most of the config. - All of those subselections of esnext like esnext.array are implied by esnext so you're duplicating there - exclude isn't necessary like that. Exclude is to exclude something that was previously included, unless you have a node_modules directory inside src it does nothing - You can change include to just src, tsc will automatically resolve the whole directory glob....

Precondition Command

In a global precondition, is it possible to get the command object for the command the precondition is being run on?
Solution:
The command is the second parameter of the run function. Example: https://github.com/sapphiredev/framework/blob/main/src/preconditions/Enabled.ts

Is documentation page outdated?

I'm a first-time sapphire user, but I couldn't find an answer to my question. The documentation says this website is written for the 3.x version of @sapphire/framework The last published version is 5.0.7...
Solution:
Updated now

Precondition i18n

Per this example here https://www.sapphirejs.dev/docs/Guide/preconditions/global-preconditions is it possible to like use one i18n function for it to work for all them with the message or do I have to take special precautions and check which type it is?
Solution:
If so, no, but you don't send messages through the preconditions anyway. You to that through listeners. And you identify the identifier there then send the translated message. See https://github.com/skyra-project/skyra/blob/main/src/listeners/commands/messageCommandDenied.ts for an example.