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 to push incomplete .env file to repo?

https://github.com/sapphiredev/gemboard/blob/main/src/.env -> Wondering how this environment file is easily pushed with the token removed (i assume) automatically. Is there a hook/gitignore to setup to automatically remove specific tokens from the environment file or is there a separate .env.local file that is excluded from the repo?
Solution:
There are separate env files, but basically you can use .env.development.local for development tokens/secrets, and .env.production.local for production ones. They're not pushed because .gitignore: https://github.com/sapphiredev/gemboard/blob/main/.gitignore#L24-L27 The reason why the extra files work (when dotenv wouldn't load further than just .env) is because the project uses @skyra/env-utilities (dependencies in package.json), which loads them, more information on the package's README....

Command not registering

for some reason, this command is not registering and is registered on parent file, I am doing something wrong?
No description

sapphire cli not working

Trying to start up a new project with sapphire cli and getting this error. Using the latest version
Solution:
Update your globally installed CLI to the latest version. That folder is from a very old version.
No description

Fuzzy Search

So I'm trying to prevent the bot from finding users if in the command only 1 character of their name was provided
await args.pick('member', { context: { performFuzzySearch: false } }).catch(() => {});
await args.pick('member', { context: { performFuzzySearch: false } }).catch(() => {});
...
Solution:
await args.pick('member', { performFuzzySearch: false }).catch(() => {});
await args.pick('member', { performFuzzySearch: false }).catch(() => {});
...

I keep receiving this error when using @ApplyOptions.

TS1238: Unable to resolve signature of class decorator when called as an expression.   The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
TS1238: Unable to resolve signature of class decorator when called as an expression.   The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
This only happens on some commands, especially new commands that I create by generating using the CLI or copying other existing commands....
Solution:
It's alright, it was something with my tsconfig, but that was automatically added by SapphireCLI.

Autocomplete handling in subcommands

I was wondering how would i handle autocomplete interactions inside subcommands? i have a subcommand group the command has autocompletion on some of it's options is it possible to handle autocompletion within the subcommand class or do i have to handle it in the listener?
Solution:
It's the same as a normal command, but instead of just checking the focused option you can check the subcommand and subcommand group too. ```ts public override async autocompleteRun(interaction: Subcommand.AutocompleteInteraction) { const subcommand = interaction.options.getSubcommand();...

Any reason as to why this event wouldn't be firing?

```ts import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener, type MessageCommandErrorPayload, UserError } from "@sapphire/framework"; import { EmbedBuilder } from "discord.js"; //import { captureException } from '@sentry/node';...
Solution:
What are the names of all the files? Names have to be unique per piece type, even across folders. So no 2 files called error for example. Or if you do want that, set the name property in applyoptions

Can't get working in Deno

I've been told Sapphire works in Deno, but when I tried to run my project as-is, I get this error.
Solution:
I'm going to use this message to mark as resovled with @Answer Overflow. The TL;DR is that Deno's node modules compatibility is kind of garbage and the solutions are - Stick to NodeJS. @vladdy and I are of the opinion that OP's issues with Node can be solved with Node, it just requires some environment setup. - Use Bun instead of Deno, we fully support it and it does have proper support for node modules....
No description

How to use @sapphire/decorators?

I tried using it but am getting this error: Unable to resolve signature of class decorator when called as an expression. The runtime will invoke the decorator with 2 arguments, but the decorator expects 1. ...
Solution:
add experimentalDecorators to your tsconfig or extend @sapphire/ts-config/decorators

Is it possible to send an image using `plugin-api`

I have a leveling bot and a dashboard for it, i was wondering if there was a way to get the users rank card from the api instead of generating the image on the dashboard.
Solution:
response.setContentType(MediaTypes.ImagePng).status(200).end(bufferOfTheImage) if i remember correctly. Let me know if it works. We could add utility methods for this.

How to get ID of command?

How can I easily get the ID of a registered command for the purpose of mentioning it? I'll be mentoning the command from another command.
Solution:
The id field isn't stored in Sapphire because it is stored in DiscordJS already. Sapphire will have logged the IDs on initial register if you didn't use bulk overwrite (in which case you should have also added it to idHints) but to get it dynamically this is the code: For Global Commands ```js import { container } from '@sapphire/framework';...

[ARGS] this.error errors in the console

[ERROR] Encountered error on message command "ban" at path "D:\Gits\dqm-neo\src\commands\ban.ts" ArgumentError: Username must be less or equal than 20 characters long.
[ERROR] Encountered error on message command "ban" at path "D:\Gits\dqm-neo\src\commands\ban.ts" ArgumentError: Username must be less or equal than 20 characters long.
my arg takes a string and checks if the username length is less than or equal than 20 characters and more than 3 characters...
Solution:
just found out about messageCommandError.ts
No description

Memory Leak

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 interactionCreate listeners added to [Client]. Use emitter.setMaxListeners() to increase limit I recently got this error, my bot only has 2 slash commands and 4 context menus, which are not used much, I already asked in the djs server and they said to go ask here instead...

Slash command not updated

Hi, I have a move channel command with options setup as in picture. On the channel command I did not previously have the channel type option set. I have since updated it (some months ago) and it looks like the slash command was not updated since I can still use category type channels. On my dev bot I unregistered and reregistered the command and that fixed it. Is this a bug or?
Solution:
Released in v5.0.7
No description

Class constructor _Listener cannot be invoked without 'new'

i just got the listener from the docs and now it's sending this warning ``` Error when loading 'D:\Gits\dqm-neo\src\listeners\ready.ts': TypeError: Class constructor _Listener cannot be invoked without 'new' at new ReadyListener (D:\Gits\dqm-neo\src\listeners\ready.ts:23:42)...
Solution:
for those using next.js set your version on something different than es5 (i used es2016)

Sapphire's approach to components

Does sapphire introduce a new way to handle component interaction? Non persistent components, If so what are they
Solution:
If you mean a scenario where the bot would reply with a component and then listen to that, I'd recommend either: 1. If something simple like a Yes/No button, just use message.awaitMessageComponentInteraction 2. If inputs result in completely separate functionality like Singleplayer vs Multiplayer, stringify all necessary state and add it to the custom ID, then parse it out in separate interaction handlers...

Certain amount of infractions per page

```js let warnings = await db.find({ user: user.id, guild: message.guild.id, automod: flagCheck ? true : false...

Docker volume issue

Hi, trying to run my bot inside of a docker container on my server (exposing the workdir to the host for changes). Yes, these files are stolen from the official repos. Current bind shows no files on the host and the attached error when trying to run the container. If I run the container without any mount points then it runs fine....
Solution:
No but you can make the GH action that also published the new image to run that command on the server

Checking for flags in message commands

I'm trying to add a --silent flag which if present will make the punishment silent (the user won't get a dm). Is this possible through sapphire?

Get message text from ContextMenuCommandInteraction

Another noob question, sorry! Pretty much title. I have tried parsing the JSON object and using fetchReply() but I believe that is for the reply generated by the bot....
Solution:
See if there's anything for MessageContextMenuInteraction