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

User Install (The new update)

Hello, I am attempting to make my JavaScript d.js Discord Bot work with the new User Install feature (The new update). To do this, I need to modify the handleCommands, but this is only found with the normal discord.js framework, which leads me wondering how to add the system to make the new UserInstall feature work with my sapphire framework. If anyone could assist, I would be grateful!...
Solution:
they should still work the same way. The only thing is that the commands need to be registered with
contexts: [<values>],
integration_types: [<values>]
contexts: [<values>],
integration_types: [<values>]
inside of the command registry. If youre using the builders i dont think they currently support it, but if youre putting in the raw API data it should work just fine...

Translated Subcommand does not register because a error

``` 2024-03-22 19:16:49 - INFO - ApplicationCommandRegistries: Initializing... 2024-03-22 19:16:49 - ERROR - Encountered error while handling the command application command registry for command "language" at path "K:\JS Projects\rubyvoice-bot\dist\commands\settings\language.command.js" ExpectedConstraintError > s.string.regex 2024-03-22 19:16:49 - ERROR - Invalid string format 2024-03-22 19:16:49 - ERROR -...
Solution:
ahhh, found out! was a space and because not lowercase

Interaction

its just a dumb question , but i didnt manage to find it on the doc , i might have missed the part , i got an /command with a addStringOption , that have a addChoice , how can i get the addchoice the user picked , to be displayed somewhere , like interaction.getChoice or something like that

Just curious, can I declare a map of string to Class on container as a type?

wondering if this is okay lol
Solution:
yeah I figured if I used the container.configHandlers.get and it's undefined then I create & set it
No description

Slash Command Permissions

How to make a slash command accessible by any one ?!
Solution:
Yeah it should. Does the user have the Use Application Commands permission?

Slash Command : How to set the type channel option to voice only

``` public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) => builder...
Solution:
.addChannelTypes() as an example addChannelTypes(ChannelType.GuildText)...

Is there a way to make precondition in interaction be ephemeral?

cause with the OwnerOnly the CLI gives it throws the error in a regular reply.

Default Permissions

Hello! As i do slash commands only, is it possible to set the Default Permission, so that the guild admins can override perms if they want?
Solution:
```ts import { Command, type ChatInputCommand } from '@sapphire/framework'; import { applyLocalizedBuilder } from '@sapphire/plugin-i18next'; import { PermissionFlagsBits } from 'discord-api-types/v10'; ...

Issue with path aliases not working when using imports (TypeScript)

Not sure what exactly is going on, normally I'm only using TS paths like "@lib/*": ["src/lib/*"] but I wanted to start implementing something similar in my bot to make it so I don't have a bunch of ../../../ and whatnot when I'm having to import certain types/classes/etc.. Never had any issues with this while using NextJS, but I assume this has to be an issue with my tsconfig/package.json files. This is the error I'm getting at the moment: ```...
Solution:
The error is a NodeJS runtime error. Not a TS compile error. TS doesn't recalculate aliases and output resolved paths. You need to also configure your aliases in package.json subpath imports. Note that you also need to switch to # instead of @ then because that's what node requires. https://nodejs.org/api/packages.html#subpath-imports You can look at various examples from /tag bots ( @Spinel command)...

"ChatInputCommandError" listener not firing for subcommands

ChatInputCommandError.ts: ```ts import { ChatInputCommandErrorPayload, Events, Listener } from '@sapphire/framework'; import generalErrorEmbed from '../lib/embed-presets/GeneralError.js'; ...
Solution:
SubcommandPluginEvents

how do you make these using sapphire?

^
Solution:
and requires ur bot to be verified
No description

commands

Is there any way to ignore a command inside the commands folder ?! i have an abstract class that extend Command ! but i do not want to set the abstract class as command , only the child classes that extends the abstract class...
Solution:
move BaseSelfRoleCommand out of the commands folder

Decorators Message Context?

The decorators don't really say, can I use them on top of an interaction? If not, what's the recommended flow to use the decorators e.g. RequiresGuildContext() on things like a command rather than a subcommand?

Scope of Command Classes?

Hi just curious, what's the scope of command classes? Is a class created each time you run the command, or ```py export class ConfigCommand extends Command { supportChannel: Channel | null = null; settingsEmbed: EmbedBuilder | null = null;...
Solution:
An instance is created before the bot logs in and afterwards that same instance is always referenced. Thank god because otherwise perf would be dogshit

Command is not registering

i have a issue with register a translated command.. Current code is ```ts import { ApplyOptions } from '@sapphire/decorators';...
Solution:
@Fabi My current suspicion is that you havent setup @sapphire/plugin-i18next properly. Here is a zip with files that are based on the CLI generated template that show what needs to be done The important parts are: 1. Calling the /register of the plugin 2. Configuring the languages for the plugin (see the config in src/index.ts)...

logger doesn't work properly

Hello, so I faced a logger problem. I registered the plugin in src/index.ts and plugin doesn't register properly, I think. Logs looks like a basic sapphire log without a plugin. How can I fix a problem with logger plugin?
Solution:
"@sapphire/plugin-logger": "^3.0.7",
That's an old version. Please update to v4.0.2 on that note, these also....
No description

Slashcommand Option Translation

Hello! How do i translate slashcommand options?, didnt saw a example. Thanks!

Globally setting the guild in which to register commands by default

Even though I'm setting ApplicationCommandRegistries.setDefaultGuildIds(<GUILD_ID>); before <SapphireClient>.login the commands are still being registered globally. The commands do not have the guildIds option set.

Who is Sapphire for ?

I was reading about the framework. So if I understand, that is basically just adding an opiniated structure to your code? Assuming you have made big bots and know your way with ts/js, is that something that is still commonly used by proficient bot developers, or is it something whos more aimed at helping beginners with their journey?...
Solution:
either way, the point is that either you can choose to maintain a lot of code for command handling yourself (especially if you use slash commands), or use a framework and have that work done for you.

Subcommands Not Working

Hello, I am trying to make my subcommands "tidy" by using separate files, but the functions aren't even running. server.command.ts ```ts import { Subcommand } from "@sapphire/plugin-subcommands";...
Solution:
@Enrique I looked into the issue and I can run subcommands just fine. I created a PR with the changes I made https://github.com/b1nzeex/dvs-discord-bot-v2/pull/1 The notable ones are: - Reinstalling dependencies, part of updating to yarn v4 - Setting up the initial Prisma migration so the schema is created. You connect the database, so you need to make sure Prisma can actually interact with it. Without this the application should just crash at init anyway...
No description