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

Multiple guilds

Any suggestions/advices on how to properly manage multiple guilds at once? How would I go over handling a command that has the same name and is supposed to be in few guilds but execute based on different roles etcetera? If I had to write it all in one script-file, it'd become such a mess. Hopefully readers can comprehend it...
Solution:
Register globally and set defaults for permissions then have guild moderators set the actual values they want to set through the discord UI.

Bulk upgrade commands to remove unregistered ones

Hellow How we bulk update commands (slash but also contectuals) with sapphire ? or in more general deleting unregeistered commands ? i tried register behavior as BULK_OVERWRITE but i didn't work...
Solution:
ok mb environment issue, idk why docker wasn't rebuild image

Compilation Errors in Dependencies

Hey, I'm trying to create a new project, but when running tsc to build the bot I get many errors. ```ts node_modules/@sapphire/result/dist/cjs/index.d.cts:832:5 - error TS2416: Property 'isOkAnd' in type 'ResultOk<T>' is not assignable to the same property in base type 'IResult<T, any>'.
Type '<R extends boolean>(cb: (value: T) => R) => R' is not assignable to type '<R extends boolean>(cb: (value: T) => R) => this is ResultOk<T> & R'....
Solution:
Oh sorry, seems like I found the solution in an older post ๐Ÿ˜… Didn't notice it at first because of the title. For anyone searching: https://discord.com/channels/737141877803057244/1255166271432163399/1255178804385812571...

manual task compiler error

The heading might not be the best here but I tried searching and the docs but can't figure out what I am doing wrong. I used the scheduled tasks plugin. I've been using it for a while and my bot runs certain pattern tasks with no issue. I want to create a manual task that deletes a message if it's deletable after a set period of time. I followed the directions here https://github.com/sapphiredev/plugins/blob/1f0ca075501324013b7a79410ee4bc04ebad9720/packages/scheduled-tasks/README.md#manual-task-example ...
Solution:
something like this:
this.container.tasks.create({ name: 'delete-message', payload: { message } }, { delay: offset })
this.container.tasks.create({ name: 'delete-message', payload: { message } }, { delay: offset })
...

Errors loading Commands and Listeners on bun run

When trying to run application via bun run, receive errors for each command and listener created. Here the following error: ```bash Error when loading '/home/thrump/projects/botc/src/commands/createChannel.ts': 9 | LoaderErrorType2["UnknownStore"] = "UNKNOWN_STORE";...
Solution:
i see the issue now: the documentation mentions to set your "main" in the package.json to the src/index.js, so in my head i assumed it needed to point to my src/index.ts. but i guess based off the outDir in the tsConfig, have to point to dist/index.js...

Hide Slash/Context menu commands

I have a number of Slash and Context Menu commands that I would like to hide, unless the user holds certain permissions. These permissions, I want to define by role (e.g, the 'Moderator' role). The commands should only be visible for users who have that specific role. ...
Solution:
You cannot. Through code you can only set it based on a permission level, not a role level. Discord API rules. The solution here is to set it to administrator in code then change it manually in the UI...

how would i know if a certain precondition is in a command?

i didnt rly find any function/feature for checking for a precondition ```ts const fields = commands.map((v) => { const prefix = v.supportsMessageCommands() == v.supportsChatInputCommands() ? "" : (v.supportsMessageCommands() ? "!" : "/")...
Solution:
Use command.options.preconditions

Crosspost listener not working

I have a bot listening for message updates, and then filtering it out to be a crossposted message, but it isn't working ```ts import { Events, Listener } from "@sapphire/framework"; import { Message, MessageFlags } from "discord.js"; import { lexer } from "marked";...

can i use preconditions in listeners

i have a few checks needed before running a group of different listeners, right now i have these checks in a helper function that i run at the start of each listener, but it would be nice to have them run automatically if i add a precondition
Solution:
no but preconditions are just glorified if checks so just extract the functionality to a function and call that function in both places

Listeners not registering?

I'm using sapphire with TS & TSUP, but registers aren't working... listener code: ```ts import { Events, Listener } from "@sapphire/framework"; import { ActivityType, type Client } from "discord.js";...
Solution:
could you try changing main to dist/main.js

error when trying to run bot

Solution:
edit it to "typescript": "~5.4.5" and run npm install/yarn/pnpm whatever...
No description

Assigning ID hints outside of builders

Is it possible to assign id hints outside of builders? Currently it's impossible to juggle id hints between the dev bot and the main bot and I was wondering if there's a way to do this outside of the builder, maybe before the client is initialized

idhint & command id

Is sapphire framework supposed to assign command id to every command whether it is global or guild-only? also, can we put idHints directly in the slash commands or not? if not, what do you suggest...
Solution:
first question is a yes because that's just how the Discord API works (as well as databases in general for that matter). Every entity has an id. A message (like this), a user, a guild (server), channel, thread, forum post, etc, they all have ids. For your second question, I'm not exactly sure what you're asking. There is only 1 valid place to put the idHints and that's as part of the registerChatInputCommand / registerContextMenuCommand function's second paramater (options) ```ts public override registerApplicationCommands(registry: Command.Registry) {...

Cooldown filter precondition

I wish to create a cooldown for a command but instead of filtering by user (cooldownFilteredUsers), I want to filter it with a precondition (ie user has a certain role in the guild). What is the best way to do this? (I don't want to deny the command usage, just apply a cooldown for users who do not meet the precondition.)...

API Authentification

Does sapphire have a way to implement authentification to the api routes so that for, example, the api can only be accessed thru the bot dashboard?

PM2 issues

Hello. I'm trying to use PM2 (installed globally) with NVM and I'm having trouble getting it to work. Any idea what I might be doing wrong? Is it because of TSX?
No description

Help with manually setting path for stores

I am using Nx, a monorepo framework. The way it configures it's builds, makes it so that it is not possible to set the main entry in package.json, because Nx also uses that entry to do some preprocessing/validation before running SapphireJS' entry main.js I tried manually setting the path via container.stores.registerPath('./main.js') where SapphireJS client logs in, but with no luck. Any advice/direction would be much appreciated. registerPath()...
Solution:
You can also set the root directory so it doesn't rely on the main entry in package.json and is instead a path relative to the main files' directory (import.meta.url in ESM or __dirname in CJS). However, if you want to load the pieces programmatically, you can use this guide: https://sapphirejs.dev/docs/Guide/additional-information/registering-virtual-pieces If you go for the latter, you can use the Sapphire CLI, you can write sapphire gl in your terminal and it'll generate all the _load.js (or _load.ts depending on your configuration) files ready for usage...
No description

Slash commands failing to register

I deleted my dist folder because I wanted to 'refresh' the compiled code, and right after I noticed that only 2 of my commands are registering now, them being escalation-manager and shortcut-manager. I don't get what went wrong since it was working fine earlier but maybe someone can shine some light into this?

Chat input command IDs

I have a function that needs to get the id of a chat input command to process some logic, and I was wondering how I could get the id? Obviously it's stored in container.stores.get('commands') but I don't know where to go from there.
Solution:
import { ApplicationCommandRegistries } from '@sapphire/framework';

ApplicationCommandRegistries.acquire('commandNameHere').globalChatInputCommandIds
import { ApplicationCommandRegistries } from '@sapphire/framework';

ApplicationCommandRegistries.acquire('commandNameHere').globalChatInputCommandIds
...

Interaction create and custom commands

I have a system with shortcuts (basically a command that punishes a user with a defined reason and duration, e.g something like ,spam <user>) and I'm trying to port them to my sapphire bot, however, I'm unsure if adding an interaction create event for chat input commands would mess with sapphire's handlers. My guess is that It won't if it can't find a command that matches the name of a global command but I'd still like to make sure. Can anyone confirm this?
Solution:
Ah no you can't do that through sapphire command classes but you can implement the Events. UnknownChatInputCommand event instead of interactionCreate which will ensure that the interaction is at least a chat input command and not another type of interaction.
Next