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

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

Sapphire with TypeScript & Bun

How does sapphire import files? Does it work fine with bun with typescript?
Solution:
Bun is supported yes

Cant get bot to work when put bot related files to another folder in src

Hello i try to put my botfiles to src/bot/ but the bot wont work if i do this: ```cmd └───src │ index.ts...
Solution:
either drop the "bot" subfolder and set main to dist/index.js in package.json OR override the automatically resolved folder by setting baseUserDirectory in the client options
No description

Nested Router with @sapphire/plugin-api

Hello guys, iam really new to this framework. i would like to integrate my express to my sapphire project. In my old project i was using nested routers. Here are some references from my old project: ...
Solution:
routes/servers/server.ts with a route option in the constructor of servers/:serverId routes/servers/server/config.ts with a route option in the constructor of servers/:serverId/config example: https://github.com/skyra-project/skyra/blob/main/src/routes/guilds...

Extending Listener base class

So I wanted to extend the Listener base class by running some code for every listener before the actual run handler is invoked. Ideally I'd like to shim it somehow so existing listeners still just implement run so removing or adding more shims like this is easily possible without renaming methods implemented in the listener itself.

What's the point of having a "container" object exported which consists of client and other stuff?

What I found kind of unique in sapphirejs is that it uses an object called container which consists of client, stores, etc. But how is that better than just exporting client and stores directly? For example, instead of using this.container.client in command classes, why is not better to just use this.client?
Solution:
this.container (or container for that matter) is an object that can be extended by plugins and bots. In base @sapphire/pieces it's an object with only the PieceStore, but @sapphire/framework augments it by adding client: SapphireClient in the same way as plugin register their augmentations. For example, if you use @sapphire/plugin-api, you'd have access to container.api. In fact, some plugins do not require discord.js or even Sapphire due to this system, which allows some projects to be library and/or framework agnostic. Another advantage to this approach is that we do not pollute the discord.js Client class with a lot of properties. For example in my bot, I have a lot of properties:...

Listeners and Index.js

Hello, I basically made a Giveaway System, but I have a code that needs to be in index.js and 1 that needs to be as event, but right now I am clueless as where to put the index.js to put it into perspective of normal discord.js framework, 1 code ness to be in the inde.js and the other in the events folder but I don't know where to put these code using the sapphire framework. When I put the code that's supposed to be in my index.js file, i get this error: ```js /home/container/src/index.js:22...
Solution:
I can already tell that your event code is invalid btw. You cannot module.exports inside a run method. Nor would you even want to. Also sapphire already implements messageRun for handling commands, that's the whole point of using sapphire. Anyway I have no idea about your problem but it's not sapphire related. The error is saying that Giveaways manager is not a constructable class. Why that is, I don't know. Sidenote that giveaway bot exists and no offense but realistically no one is gonna use your bot over it, so unless you're just code practising, don't expect another giveaway bot to grow much. You're very unlikely to have a killer niche feature that giveaway bot doesn't cover. This is the problem will all discord bots, if you don't touch a niche yours won't grow much....

Stricter type checking for string command choices

Hi, was wondering if this is possible. In this example I am doing a command that can change my bot's status from Online to Invisible/Idle/Dnd. I want to ensure that the value choices in addChoices have the PresenceStatusData type in case the string values are changed in a future API....
Solution:
or just type assert

WIll this work?

``ts public override registerApplicationCommands(registry: Command.Registry) { registry.registerChatInputCommand(command => command.setName("ping").setDescription("Pong!"), { idHints: [${this.container.client.id}`], });...
Solution:
no, the id is meant to be the id for the command once its been created initially iirc i could be wrong on that, i dont 100% remember since i always use BulkOverwrite...

Accessing data in subcommands

I was wondering if there any way of accessing all the data passed in the subcommand without having more than one function for it?

Issue with inviteCreate event

Hello. I have an issue with the inviteCreate event where it won't fire unless the invite created has some sort of uses limit. is this intended?

Should i acquire every command or only once

Hello I just got interest to Sapphire and when i was reading advanced doc for registering commands outside of classes (in my case in a yml file) i saw that acquire a registry is necessary but i was wondering if i have to acquire multiple registry or not ? and also what registry id would be usefull for ? Thx...
Solution:
Usually you get a registry keyed by whatever you want it to be keyed as, usually a command, and then you register commands in it

no error event on subcommand precondition

what event fires when a Subcommand's precondition (on a subcmd, not the whole class) fails? i'm not getting it to SubcommandError or commandDenied

apply precondition to only one Subcommand?

I was wondering if there's a decorator or something, or if I need to run the logic manually.
Solution:
Oh I'm blind, there's a "preconditions" in the spot where you put the command names in the options.. Nevermind!

Ready event does not run

```ts import { Listener } from "@sapphire/framework"; import { Client } from "discord.js"; export class ReadyListener extends Listener {...
Solution:
Had to put the event file in Listeners folder

Error when clicking button

error: https://srcb.in/dIL4feMtz6 code: https://srcb.in/MGmSNTYXw6 I tried using Message Component and ButtonType ...
Solution:
ah I see thank you

Prevent commands from being ran on DMs and prevent bots from using commands by default

did Sapphire recently add this behavior stated in the title? I recently removed Preconditions that prevented this and looks like it's still blocking commands from being ran on DMs or prevent bots from using commands, which is what I want
Solution:
Bots have been prevented from running commands since day -1 of sapphire, quite literally as that was already a thing it was still skyra framework. Sapphire didn't change anything in regards to running commands in DMs. Has always been the same too. All changes and releases are posted to #Announcements...

Button doing nothing

const button = new ButtonBuilder()
.setCustomId("COB")
.setLabel("Custom Options")
.setEmoji("⚙️")
.setStyle(ButtonStyle.Secondary);
const button = new ButtonBuilder()
.setCustomId("COB")
.setLabel("Custom Options")
.setEmoji("⚙️")
.setStyle(ButtonStyle.Secondary);
...
Solution:
the folder for your buttons is incorrect then. As per our guide the folder should be called interaction-handlers: https://sapphirejs.dev/docs/Guide/interaction-handlers/what-are-they

InteractionOptionResolver pleasing TypeScript

I have an HTTP interactions app that utilizes @discordjs/core/http-only. Currently, I have my own class for resolving application command options, however I'd like to use the one provided by @sapphire/discord-utilities. The only setback I'm having is passing the interaction to a new instance of InteractionOptionResolver. Its constructor is typed as
constructor(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction)
constructor(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction)
However when I give it a variable typed as APIApplicationCommandInteraction which I thought would work given its type definition includes it, I get a nasty error of it missing a target_id, which I know stems from context menu command-related stuff. I get similar missing property errors with APIContextMenuInteraction or APIChatInputApplicationCommandInteraction - yada yada missing users property or just not assignable at all. My question is, before I go casting or @ts-ignoreing or whatnot, is there any realistic way to resolve these errors so I can use this utility class in TypeScript? Am I missing some simple step? Is this just TypeScript limitations? Node: v18.17.0...
Solution:
Can you try forcing the discord-api-types version through package resolutions / overwrites?
No description