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
Ddoqe4/8/2024

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 )...
Ssecre4/7/2024

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...
BBaylem4/7/2024

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.
NNXFASTE4/7/2024

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?
TTechSquidTV4/7/2024

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:...
Ff1fty4/6/2024

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
Mmallusrgreat4/6/2024

Sapphire with TypeScript & Bun

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

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
Ff1fty4/5/2024

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...
BBigBrainAFK4/5/2024

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.
Nneon4/4/2024

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:...
MMalik4/3/2024

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....
Ffluffy4/2/2024

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
AAAhmad A.4/1/2024

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...
LGLynx Gian4/1/2024

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?
Zzeyad_1553/31/2024

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?
WWeeskyBDW3/30/2024

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
Llog(n)3/30/2024

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
Llog(n)3/30/2024

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!
Zzeyad_1553/30/2024

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