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

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

Permission check in other guild

How am I supposed to make it so for example I have Invite to MTF context menu that has to invite someone to MTF guild, like, it does its job, but my point is so no person can be invited unless they have Lieutenant+ in MTF guild, how am I supposed to make this permission check? (i'd appreciate if i were to be pinged upon reply)
Solution:
@Boomeravna @UndiedGFX I got it fixed. Instead of passing just userid, I passed entire member object & did member.fetch(true) and of course made sure I am fetched in the 'mtf' guild. Hopefully it is understood

Registering multiple paths for pieces

I was wondering if it's possible to register multiple paths for sapphire's pieces (commands, listeners, preconditions, etc). The reason why I want to do this is because I override most of the core listeners to add my bot's customization options and I wanted to separate them

EMPTY_MODULE

why I get error from parseConstructorPreConditionsCooldown when extending class Command? I want to create that class as my base class command and make it a plugin that I'm going to use on my other projects. I get the error when debugging why my class is identified as Empty_Module...

@sapphire/plugin-scheduled-tasks fails completely

Hello, I am looking to use the @sapphire/plugin-scheduled-tasks so I made a test script based off the documentation on the Github page. I rewritten the script in commonjs as I use that instead of ts. It does does not work well. It immediately fires instead of the duration as specified, it also doesn't pass any payload variables specified. Would I happen to be doing something wrong?
# The console output, which is empty
Iran {}
# The console output, which is empty
Iran {}
...
Solution:
First of all, create takes 2 parameters and you provided 3. The proper syntax is this.container.tasks.create({ name: 'name', payload: { huilde: member.guild, member }}, { delay: 9999999999 })

Global preconditions position seems to be broken

I overrode sapphire's default UserPermission precondition so I could add my own logic. This precondition specifically works fine and runs after the ones that have a position before it, however, I have another precondition that checks for channel permissions, and that one seems to run before this, even though it has a higher position I can't tell if this is a bug or I'm doing something wrong but that's what is happening...
Solution:
Well, I figured out why it wasn't running before. Since that precondition is appended into command preconditions if the requiredUserPermissions option is provided, it runs after the global preconditions

Snowflake.deconstruct return incorrect value

Hi. Im trying to decode timestamp from message id (DiscordSnowflake.deconstruct(message.id).timestamp) but it returns me incorrect value - message has been sent at 3:32 UTC and this code returns 1722023722053
No description

Overriding default permission precondition

I'd like to use sapphire's core permission precondition but I want to modify it and add my own logic. By this I mean being able to use requiredUserPermissions in the command options. Reading through the guide/docs It doesn't specify if you can override the core preconditions with your own (like you can with arguments) so I'm asking here for clarification...
Solution:
You can override any piece in framework or in any plugin by setting the same name as the piece you're overriding

Event before precondition OR access the command via MessageCommandDenied

Hi all, I have extended my Command Options to include a property shouldDeleteOnPost - which should delete the message once it has been posted. I'd like to do this in the most universal way possible - I thought using MessageCommandRun would have fired before any of the preconditions, but it seems it does not. ...
Solution:
I think I found it actually, PreMessageCommandRun - though still open to feedback about whether this is the best possible place for it ```ts import { Events, Listener, ListenerOptions, PreMessageCommandRunPayload } from "@sapphire/framework"; ...

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";...
Solution:
Discordjs handles whether the flag is set or not so you're better off consulting then why it's false when you expect it to be true. Make sure to provide a screenshot of the message in question.

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