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

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

User Install (The new update)

Hello, I am attempting to make my JavaScript d.js Discord Bot work with the new User Install feature (The new update). To do this, I need to modify the handleCommands, but this is only found with the normal discord.js framework, which leads me wondering how to add the system to make the new UserInstall feature work with my sapphire framework. If anyone could assist, I would be grateful!...
Solution:
they should still work the same way. The only thing is that the commands need to be registered with
contexts: [<values>],
integration_types: [<values>]
contexts: [<values>],
integration_types: [<values>]
inside of the command registry. If youre using the builders i dont think they currently support it, but if youre putting in the raw API data it should work just fine...

Translated Subcommand does not register because a error

``` 2024-03-22 19:16:49 - INFO - ApplicationCommandRegistries: Initializing... 2024-03-22 19:16:49 - ERROR - Encountered error while handling the command application command registry for command "language" at path "K:\JS Projects\rubyvoice-bot\dist\commands\settings\language.command.js" ExpectedConstraintError > s.string.regex 2024-03-22 19:16:49 - ERROR - Invalid string format 2024-03-22 19:16:49 - ERROR -...
Solution:
ahhh, found out! was a space and because not lowercase

Interaction

its just a dumb question , but i didnt manage to find it on the doc , i might have missed the part , i got an /command with a addStringOption , that have a addChoice , how can i get the addchoice the user picked , to be displayed somewhere , like interaction.getChoice or something like that

Just curious, can I declare a map of string to Class on container as a type?

wondering if this is okay lol
Solution:
yeah I figured if I used the container.configHandlers.get and it's undefined then I create & set it
No description

Slash Command Permissions

How to make a slash command accessible by any one ?!
Solution:
Yeah it should. Does the user have the Use Application Commands permission?

Slash Command : How to set the type channel option to voice only

``` public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) => builder...
Solution:
.addChannelTypes() as an example addChannelTypes(ChannelType.GuildText)...