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

Issue with inviteCreate event

Hello. I have an issue with the inviteCreate event where it won't fire unless the invite created has some sort of uses limit. is this intended?

Should i acquire every command or only once

Hello I just got interest to Sapphire and when i was reading advanced doc for registering commands outside of classes (in my case in a yml file) i saw that acquire a registry is necessary but i was wondering if i have to acquire multiple registry or not ? and also what registry id would be usefull for ? Thx...
Solution:
Usually you get a registry keyed by whatever you want it to be keyed as, usually a command, and then you register commands in it

no error event on subcommand precondition

what event fires when a Subcommand's precondition (on a subcmd, not the whole class) fails? i'm not getting it to SubcommandError or commandDenied

apply precondition to only one Subcommand?

I was wondering if there's a decorator or something, or if I need to run the logic manually.
Solution:
Oh I'm blind, there's a "preconditions" in the spot where you put the command names in the options.. Nevermind!

Ready event does not run

```ts import { Listener } from "@sapphire/framework"; import { Client } from "discord.js"; export class ReadyListener extends Listener {...
Solution:
Had to put the event file in Listeners folder

Error when clicking button

error: https://srcb.in/dIL4feMtz6 code: https://srcb.in/MGmSNTYXw6 I tried using Message Component and ButtonType ...
Solution:
ah I see thank you

Prevent commands from being ran on DMs and prevent bots from using commands by default

did Sapphire recently add this behavior stated in the title? I recently removed Preconditions that prevented this and looks like it's still blocking commands from being ran on DMs or prevent bots from using commands, which is what I want
Solution:
Bots have been prevented from running commands since day -1 of sapphire, quite literally as that was already a thing it was still skyra framework. Sapphire didn't change anything in regards to running commands in DMs. Has always been the same too. All changes and releases are posted to #Announcements...

Button doing nothing

const button = new ButtonBuilder()
.setCustomId("COB")
.setLabel("Custom Options")
.setEmoji("⚙️")
.setStyle(ButtonStyle.Secondary);
const button = new ButtonBuilder()
.setCustomId("COB")
.setLabel("Custom Options")
.setEmoji("⚙️")
.setStyle(ButtonStyle.Secondary);
...
Solution:
the folder for your buttons is incorrect then. As per our guide the folder should be called interaction-handlers: https://sapphirejs.dev/docs/Guide/interaction-handlers/what-are-they

InteractionOptionResolver pleasing TypeScript

I have an HTTP interactions app that utilizes @discordjs/core/http-only. Currently, I have my own class for resolving application command options, however I'd like to use the one provided by @sapphire/discord-utilities. The only setback I'm having is passing the interaction to a new instance of InteractionOptionResolver. Its constructor is typed as
constructor(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction)
constructor(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction)
However when I give it a variable typed as APIApplicationCommandInteraction which I thought would work given its type definition includes it, I get a nasty error of it missing a target_id, which I know stems from context menu command-related stuff. I get similar missing property errors with APIContextMenuInteraction or APIChatInputApplicationCommandInteraction - yada yada missing users property or just not assignable at all. My question is, before I go casting or @ts-ignoreing or whatnot, is there any realistic way to resolve these errors so I can use this utility class in TypeScript? Am I missing some simple step? Is this just TypeScript limitations? Node: v18.17.0...
Solution:
Can you try forcing the discord-api-types version through package resolutions / overwrites?
No description

Javascript

Alright guys, quick question if i am new to javascript (i want to learn typescript by the way.) and discord developement in general. Where should i start from, and what do i need to learn?

Any way to add a sort of "middleware" to all listeners

Is there any way to have something like a middleware or precondition for all events? I want to delay all eventlisteners by a certain number of milliseconds in my Bot so audit logs can catch up. The bot only does logging and nothing else. no commands or anything.
Solution:
didnt even see the 2nd argument for the event

Are my slashcommands guild based or global?

When I use registerApplicationCommands (like shown in the picture) does that command get registered in a single guild or globally (in development environment)? and if it is registered globally, can I made it so it gets registered in a test guild only when NODE_ENV is dev?
Solution:
global, and you can set guildIds in the second paramater of registerChatInputCommand, if you set it to an empty array or undefined then they're still global so just do a simple ternary check of process.env.NODE_ENV === 'development' ? 'myguildid' : undefined or leverage the same in Globally configuring guildIds if you want it to count for all commands
No description

Two Commands In One File

when i export chat input command and user context menu command in one file it reads the first export only. what's the problem ?
Solution:
Anyway you should just register them in the same class and implement both chatInputRun and contextMenuRun instead of having 2 classes

Question regarding client.login()

A bit of a curiosity question, I noticed that you can use await client.login(); without providing the token if you use @skyra/env-utilities. So my question is like what does the login get as the token if token is not provided? process.env...?...
Solution:
yeah, its "process.env.DISCORD_TOKEN"

@sapphire/type error

Error when loading '/home/matthew/projects/ts/waddlebot/src/commands/General/eval.ts': error: Cannot find module "/home/matthew/projects/ts/waddlebot/node_modules/@sapphire/type/prebuild/type-node-v115-linux-x64-glibc-2.29/type.node" from "/home/matthew/projects/ts/waddlebot/node_modules/@sapphire/type/dist/esm/index.mjs"
Error when loading '/home/matthew/projects/ts/waddlebot/src/commands/General/eval.ts': error: Cannot find module "/home/matthew/projects/ts/waddlebot/node_modules/@sapphire/type/prebuild/type-node-v115-linux-x64-glibc-2.29/type.node" from "/home/matthew/projects/ts/waddlebot/node_modules/@sapphire/type/dist/esm/index.mjs"

logging

Is there anyway I can log to console every time a command or a listener is ran?
Solution:
There are events for command runs

Random Error

So everything was working fine and all but then out of no where it's decided to go and throw this on my preconditions. I can't seem to find anything about any updates or anything like that so some help would be appreciated...
Solution:
Change Piece.Context to Precondtion.LoaderContext. It's a type only breaking change that we pushed somewhere in a minor version of v4. I forget which exactly.
No description

DiscordAPIError[10062]: Unknown interaction

So it keep giving me unknow interaction, while im using deferReply normaly. Also when i try to log something it don't log for some reasosn. i use this.container.logger.debug
No description

Scheduled Tasks with Common JS

I am looking to do a task every 2 minutes, I want to use scheduled tasks but seems like all the examples are in Typescript/ESM, can anyone show or explain how to use it with CommonJS?
Solution:
Just change the import syntax for require and remove the types. The code stays the same.

Cannot find module issue though the module is exported.

Please check the screenshot attached with this post.
No description