Sapphire - Imagine a Framework

SIA

Sapphire - Imagine a Framework

Sapphire is a next-gen object-oriented Discord.js bot framework.

Join

sapphire-support

discordjs-support

old-sapphire-support

old-discordjs-support

old-application-commands-and-interactions

Can't use Sapphire CLI

I installed sapphire globally using yarn but for some reason it's not working
Solution:
add your yarn global bin to your PATH

pollSync error

I just started the bot and I get this error by default ``` C:\Users\Charl\OneDrive\Escritorio\Rox\node_modules@sapphire\utilities\dist\lib\pollSync.js:10 AbortSignal.abort().reason.constructor...

Production mode?

I'm having issues disabling the DEVELOPMENT MODE. .env doesn't allow setting NODE_ENV and it doesn't work based on the name of the .env file. I've also tried using MODE per a Stack Overflow thread I found but that didn't work either. Is there not a solution where I just copy the built files over and change a setting somewhere?...

Running commands manually

Is there a way to run commands manually, without a message/interaction making Sapphire do it?
Solution:
Example ``ts // or, if in a command class, just use this.store` const commands = container.stores.get('commands');...

Regarding containers

Hello! With regards to the example repos with setup.ts, is every property in the container already available like the Client at startup?
Solution:
Which one exactly are you talking about? There are 3 examples that have a setup.ts and each has some unique content, and none use container. At any rate, the idea of setup.ts is that it is called before you can new SapphireClient, which happens automatically through line 1 at https://github.com/sapphiredev/examples/blob/main/examples/with-typescript-starter/src/index.ts, by calling just import './lib/setup.ts' instead of something like import { x } from './lib/setup.ts' that file i...

Custom Client Event

How to make it right when I want to custom event for client for example: client.emit('someEvent', data) then can I use framework listeners for that events ? like create someEvent.ts file so that I can use or I need to do client.on('someEvent', handler) for it ?...
Solution:
You don't need to do anything. Just make a listener with the file name and/event name prop set to the custom name. In case of the latter you just have to use module augmentation to ensure it gets detected because the event prop is keyof Client

guildMemberUpdate event

I'm trying to create a listener for the guildMemberUpdate event, and sapphire registers this listener, but the run is never executed Code: ```import { Listener } from '@sapphire/framework'; import type {GuildMember} from "discord.js";...
Solution:
remove once: true, otherwise it gets de-registered after a single call. Also make sure you have the proper intent in your client options...

Creating a custom UserError

I want to use a custom UserError to create preconditions for my subcommands. I can't find any documentation examples on it. Anyone have any suggestions so that in my custom preconditions class I can call throw new UserError and have it go to my custom function?...

Sharding via DJS and Sapphire

Hey y'all, I'm looking at the Discord.JS docs for sharding and wanting to implement that within Sapphire. From my search in this server I found to use the DJS method of using it as Sapphire doesn't support extra with that. However, there isn't a ShardManager included in Sapphire, and I still want to use the Sapphire Client options. Is that still possible with Sapphire or do I have to eliminate the SapphireClient completely (which defeats the purpose?)...
Solution:
Sapphire doesn't ship its own sharder because it works with Discordjs's, you just instantiate SapphireClient instead of Client.

Subcommand issues

I'm having an issue with subcommands where it just doesn't seem to recognize a subcommand. The following is how I register the command I'm having issues with. All of them work fine except guild whitelist. That one throws this error: https://hyperfire-dev.sentry.io/share/issue/1464c7085b934a0296005c7e7ee22553/ ...

Trouble with telling typescript the return type of fetch when using @sapphire/result

Hi there, I have a function that fetches an API using the native fetch function. The fetch is wrapped in Result.fromAsync(), and I wanted to do Result.fromAsync<Promise<APIResponse>> since I know what the API will return. The problem is, when doing Result.fromAsync<Promise<APIResponse>> Typescript says that Response is missing certain properties that I know the API will return. How would I tell Typescript I know that the fetch will return this?...

How to check if a number (the permission integer) has the manage server permission?

I need to check this, without using discordjs, only the sapphire/bitfield package I didnt understand the readme good enough, thats why im asking here....
Solution:
Solution ```ts const p: bigint = BigInt(guild.permissions); const PermissionsBitField = new BitField(enumToObject(PermissionFlagsBits)); const hasManageGuild =...

messageCreate not working with DMs

Greetings! I'm having troubles getting the messageCreate event to run with DMs. When I send a server message it all works well, but in DMs it simply refuses to work. listeners/messageCreate.ts: ```ts import { ApplyOptions } from '@sapphire/decorators';...

Setting Nicknames

Is there a good way to set a user's nickname (by userID) when using sapphire?
Solution:
👍

Sapphire not initializing correctly inside of Docker

I have a bot that works just fine when running outside of Docker, and although my Docker container starts, it does not initialize Sapphire correctly (although the ready event does fire) Outside of Docker: ``` ready...
Solution:
i fixed this by doing ```dockerfile WORKDIR /usr/src/app/services/bot/build ...

'Can't find the template.' on a template listed in the docs

When running sapphire generate buttoninteractionhandler customRole I get the error Can't find the template., however, https://www.sapphirejs.dev/docs/Guide/CLI/generating-components lists buttoninteractionhandler as a component.
Solution:
Update your globally installed @sapphire/cli making sure sapphire --version returns 1.6.1.

Issue when running mutiple bot instances on the same redis db with the scheduler plugin

I have currently 3 bots that all are executing the same code. They have a schedule that triggers every day at 0am and are using the same redis db. I recently discovered, that sometimes, the execution of the scheduled task is not executing and I was wondering if this cuold be connected to the multiple bot instances that a are connected to the same redis db....
Solution:
If so then yes. You should configure them to use different databases. Bullmq doesn't use any particular unique identifiers for its keys.