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

Type Error: "Property "sentryError" does not exist on type 'ILogger'

Ive extended the @sapphire/plugin-logger to add sentry logging, however it is still throwing type errors when I try to use said functions. SentinelLogger.ts ```ts import { container } from '@sapphire/framework';...
Solution:
If you just want to send all your errors to sentry then you don't need to extend the logger, instead set it up like so: https://github.com/skyra-project/skyra/blob/main/src/Skyra.ts Does that already help possibly?...

env/join not working properly

hi
Solution:
wait do i just need one more '..'

Issue with application commands after logging in after client#destroy()

If I login after doing client.destroy(), the bot logs in fine, but the application commands aren't registered again. Am I doing something wrong? Some example code: ```typescript client = new SapphireClient({...

Interaction handler parse never being called

```ts import { ApplyOptions } from "@sapphire/decorators"; import { InteractionHandler, InteractionHandlerTypes,...

logger

is it possible to enable how many commands are loaded etc
Solution:
Yes, you can use container.stores.get('commands') to access to all the loaded commands, it’s a Collection, so you can do .size to get the amount.

Application command registries

Before I switched to sapphire, I used to have my own system that tracked command registrations through caches and the db, and I'm wondering if I can re implement it. Is there a type of event that emits whenever a command is registered? By this I mean one that gives information like the logger does when it's set to the debug level/contains properties like the name, id, etc. I've attached an example from my previous setup just for a rough idea...
Solution:
have you considered adding @sapphire/plugin-logger? it already adds timestamps, colours, and sensible log levels.
No description

TS App does not attach event listeners once complied, works in dev

Hi, my application doesn't execute any event listeners in a compiled JS state, but works fine when booting into TS via nodemon. I've tried multiple bot accounts with replicated permissions, inside and outside of docker containers, locally and deployed, but for some reason compiling the app to JS gets the app stuck after ApplicationCommandRegistries INFO logs are fired. I also can't amend the LogLevel option on Sapphire instantiation. Any advice or insight greatly welcome! This has been driving me mad...
Solution:
For anyone that stumbles upon this in future with similar symptoms (app booting, bot is registered online in discord but events not picked up) my solution was to update package.json's main parameter to an appropriate value against the compiled JS entrypoint - in my case dist/index.js.

declaration for DetailedDescriptionCommand not working

so i declared DetailedDescriptionCommand in my index.d.ts and it's not working
Solution:
also rename it from index.d.ts to type-augments.ts

Cooldowns during command execution

Hi all, wondering if there is a way to set a cooldown using with the global cooldown precondition during command execution? Creating a system for transactions, if said transaction goes through I would like the cooldown to be x amount. Otherwise if it fails, I'd like it to be the default value. Not sure if I need to implement a custom system for this or if this can be achieved with the default tools given.
Solution:
You will have to implement a custom system for this leveraging listeners and a cache for the cool down state.

Is there a way to hide command if the user doesn't have the precondition ?

Solution:
That's correct. Server settings and setting it at register level are configuring it on the Discord API side which means a command can be hidden from users because at that point it's simply to sent to them from the API. Preconditions however are runtime checks and essentially just glorified if checks.
No description

Multiple guilds handling

Hi, so, I'm pretty new to this framework, done a couple of things, but tell me, how am I supposed to write entire getrole.js code that's supposed to retreive proper roles based on each guild, each guild = different roblox group, and It seems unimaginable on writing it all in one file, any suggestions?
Solution:
you can split it off in several files and export/import code. That said, we're not going to spoonfeed you the code because at that point we may as well write the bot for you, which in turn is a possibility (some of us including Vladdy and myself do take comissions) but against payment

Statefulness and data sharing for Pieces

Hi, let's imagine the following: you want to keep track of some data about the people who join and leave a certain voice channel. It would be convenient to store this data alongside the listener and maybe provide an interface to it directly from the listener. However, it's not fully clear how and when Pieces are instantiated. There are no examples of holding (let alone sharing) any state. How to do this right? 1. is it okay to hold state in a Listener instance? 2. if so, how to access the very same instance somewhere else?...
Solution:
use a database like sqlite, postgres, mongo, etc. Especially if you want to retain it between reboots. Otherwise, remember how DJS and sapphire do caching internally: ```ts // store.ts import { Collection } from 'discord.js'; import { container } from '@sapphire/framework';...

Missing Session ID

Error: The voice connection is not established due to missing session id
Solution:
Unrelated to sapphire. Make sure to follow the instructions from the discordjs guide: https://discordjs.guide/voice/voice-connections.html#deletion

declarations

can I put all sapphire declarations for framework & pieces in index.d.ts or it's just for arguments?

Argument not found

UserError: The argument "rarity" was not found.

Prefix

How to get prefix of executed command in messageRun? I have more of them so I need to get one sender used...
Solution:
commandPrefix probably. The difference is that prefix can be a RegExp object if a RegEx was used to run the command.

Sentry with Sapphire?

Sapphire handles all errors for me so they don't go into Sentry, what should I do?
Solution:
You should capture the error manually, for example in a listener, you can do:```ts // Other imports import { captureException } from '@sentry/node'; export class UserListener extends Listener<typeof Events.ListenerError> {...

Packages problem

Hello Hello, I manually installed the packages using the commands from the guide, but when I extended the container and declared "@sapphire/pieces" it said that I don't have that package installed, does it come with /framework or not?
Solution:
When using pnpm you have to make sure that you have the shamefully-hoist and public-hoist-pattern are set correctly in your .npmrc file. This is because pnpm will not hoist any dependencies by default and that poses a problem with how Sapphire works with module augmentation and loading files from the filesystem. Add this to your .npmrc file:...

Piece not loading when stores.register() is called

Code: https://github.com/UTCSheffield/olp-nixos-config/tree/Sean/Upgrade-tool/update-tool/server I'm using pieces without framework as it's not for a bot, When I call container.stores.register(new MessageStore()) no paths get populated and it never loads a piece, when it should be loading 1 Typescript version: 5.5.4...
Solution:
You're missing container.stores.registerPath() to set up the path, followed by await container.stores.load(); to load the pieces.

what are these

what are those numbers and where does that comes from?
Solution:
ig those are the command ids of the context menu commands
No description