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

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?...

i18n question

So this works
applyLocalizedBuilder(builder, 'commands/names', 'commands/descriptions:name')
applyLocalizedBuilder(builder, 'commands/names', 'commands/descriptions:name')
but when I use applyLocalizedBuilder(builder, 'commands:ping')...

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.

Question - handling interactions

How do you guys handle for example temporary interactions but if the user presses on it again a few hours later it should time out?
Solution:
use an InteractionCollector. Also interactions have a timeout of 15 minutes natively.

Plugin subcommands: "No subcommand was matched with the provided command."

I configured my subcommands like this: ```ts [ { name: "requester",...
Solution:
actually this also works pretty sure:
chatInputRun: (chatInputRun: Subcommand.ChatInputCommandInteraction) => this.chatInputSet(chatInputRun)
chatInputRun: (chatInputRun: Subcommand.ChatInputCommandInteraction) => this.chatInputSet(chatInputRun)
...

Application Data is null

So, I'm trying to get the owners of my application (for a team-members-based precondition for stuff like eval) but this.container.client.application has most of the data as null. It gives me the ID, flags, and that's about it. Is there anything I need to do to get that to show? Sorry if this is a stupid question it's been a while since I've worked with discord bots...
Solution:
@hyperfirers firstly, this is a discord.js question, not related to the sapphire framework. Secondly, you need to fetch the application before accessing the ClientApplication properties and methods. ```js const app = await <Client>.application.fetch();...

Language support

Is there i18n support for slash commands?

I need help to unistall sapphire because i just downloaded in vscode with knowledge abt it

i probably shouldn't have installed it without know what it is rlly is and now i keep getting errors in my code

Error listeners

Which listener catches this (image)? I have MessageCommandError and ChatInputCommandError listeners and neither one gets a log, I don't even get anything in the console. In addition, there are also MessageCommandDenied and ChatInputCommandDenied listeners...

Question - Dependancy injection

Is there DI built-in or do you recommend a certain one that fits nice with the library?
Solution:
just use what Sapphire already has - the container. In classes such as commands this.container or import { container } from '@sapphire/framework anywhere else.

Question about container in shards

Is there a way to fetch container values from another shard? I have a bot that stores data in a collection that is defined in the container, and I have a command that counts how much data is stored in this collection and the result is different between the shards

Question: Sharding support

How well does sapphire scale? Can I use the original approach of making d.js scale or does sapphire do it for me? let's say a both in 10k servers.

Combine Precondition and object available on the Command

Not sure if I've put that the right way, but I'm sure that the example will make some sense. I have this precondition that works. ```ts export class OnlyAlive extends Precondition {...

BulkOverwrite usecase

I'm trying to use BulkOverwrite to let sapphire handle all my commands but whenever I start the bot sapphire recreates some old commands which I already deleted. As far as I understand it BulkOverwrite should only register commands which are inside the project and not already deleted commands which are cached by discord Am I missing something or does BulkOverwrite work differently then I think?...
Solution:
delete your dist folder and recompile. TS will never delete files when the source TS files are deleted.

Need help persisting interaction data between consecutive interactions in Sapphire

Description I'm currently working on a project using the Sapphire framework and I'm facing an issue with persisting interaction data between consecutive interactions. I would appreciate any guidance or advice on how to solve this problem. Current Setup - I have a slash command registered in Sapphire that makes a userSelectMenu....
Solution:
There are no real best practises but your options pretty much boil down to using a cache of sorts. Either in memory by exporting some object, or a Collection (import { Collection } from 'discord.js', which is just an extension of native Map btw) or externally through a fast caching service like Redis. Either. way they are all key/value storages so keys will be customids/snowflakes/etc whatever you can use to identify later, and values whatever data you want....