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

Check if command is a slash command

```js categories.forEach((category) => { const dir = commands.filter((c) => c.category === category); const capitalise = category.slice(0, 1).toUpperCase() + category.slice(1); ...

Is it possible to send voice messages from a bot?

I have a discord bot and want to integrate OpenAI's TTS API. Problem: it just attaches MP3 files which mobile users need to download. Is there a way to send these as Voice Messages?
Solution:
Bots cannot send voice messages

Error [EMPTY_MODULE]: A compatible class export was not found.

Solution:
Simply move the file to the interaction-handlers directory (create it if you don't have one) and the issue should be solved

PaginatedMessages

how does this work? I want to use it in a warnings command which gets all the warnings from a user
Solution:
There are more expambles in the documentation than humans in the world just abouts so just look there https://www.sapphirejs.dev/docs/Documentation/api-utilities/classes/sapphire_discord_js_utilities.PaginatedMessage Or use /tag query: bots from @Spinel to get a long list of open source bots. Some use PaginatedMessage. Plenty of examples to go off of....

Automod Issue

I have this code but if someone triggers automod 3 times very quickly the bot will not timeout them. https://pastebin.com/HdxPs1Pe...
Solution:
You need to define the queue outside of the function

Dyno like help command

If i have the help data in every commands detailedDescription value, how can i make it so that when a user runs !<commandName> help it displays the help embed instead of having to run !help <commandName>
Solution:
If you're only using message commands, you could use the subcommands plugin to create a class that extends subcommand and adds a help subcommand which displays the detailed descrition. You would then have all your other commands extend that class to inherit the help subcommand.

i18n based on the user locale

Is that possible to translate a message based on the user locale outside of the interaction command using resolveKey or something else??
Solution:
Only interaction commands

command failing, no errors

```js const { Command } = require("@sapphire/framework"); const { EmbedBuilder } = require("discord.js"); class SettingsCommand extends Command {...
Solution:
Change that to Subcommand from the plugin

Slash command not working

Idk whats wrong with it, theres no error in console or anything its just doesnt work. My code: ```js const { Command } = require('@sapphire/framework');...
Solution:
nvm its problem with host, takes too long to update my files when i edit them

ReferenceError: exports is not defined in ES module scope

I am trying to run my bot and am presented with the following error ``` Successfully compiled: 13 files with swc (25.27ms) Debugger listening on ws://0.0.0.0:9229/db93ad55-46aa-4ed1-be89-f2b2b5cded3b...
Solution:
so when using pnpm you need to hoist all of @sapphire/* because otherwise TS cannot properly resolve module augmentations. I forgot the exact option but it's one of the hoist pattern options. As for your root cause, it really comes down to how you configured tsconfig. The modern standard is to use node16 for both module and moduleResolution then either use "type": "commonjs" or "type": "module" in your package.json based on whether you respectively want a CJS or ESM runtime. Once that is done and you compile with either exclusively swc (which you seem to use yet you also mention ts-node, they DO NOT work together, also we discussed the downsides of ts-node) or alternatives such as tsc / tsc-watch / tsup....

props to button

Is it possible to pass props to button ? Like a variable for example
Solution:
FWIW for @Spinel (sapphiredev/spinel on GH) we use Redis and for @Dragonite I chuck the data in customId with compression like so: https://github.com/favware/dragonite/blob/main/src/lib/util/utils.ts Keep in mind that customId is max length 100...

Multiple listeners on the same event ?

Hi, I'm trying to define two listeners for the same event (chatInputCommandError) My folder is organised as such: src > listeners >...
Solution:
Listeners detect which events they should be listening to by the file name, not the generic type. If the file name does not match the event, pass { event: '...' } into the constructor (either via @ApplyOptions from @sapphire/decorators or with super())

ChatInputCommandInteraction

How to correctly define ChatInputCommandInteraction, I tried importing it from the framework, however is returned this: TypeError: Right-hand side of 'instanceof' is not an object I'm trying to do this: I have a createError function, which sends a embed with the provided text and then deletes the message and the embed after some seconds, however I want it only reply if the variable is a interaction instance. ...

Issue with code not running after using args.rest('string') (NOT SAPPHIRE ISSUE)

```ts public async messageLink(message: Message, args: Args) { let region = 'na'; let summoner_name; ...
Solution:
Not a Sapphire related issue

messageSubcommandNoMatch listener not working

Hello again WaveLFrog Currently I am trying to handle the messageSubcommandNoMatch error. I've registered a listener for it: listeners/messageSubcommandNoMatch.ts ```ts...
No description

Invoking Command method from other command

Hey all, I’m not really sure if this is a “Sapphire support” type of question more than a TypeScript one (I’m new to TS in general) But is there any way to invoke a commands messageRun or the designated method from say another command class (something like Java reflection/does sapphire have a command handler to grab the appropriate method?) or is the best way to extract the code to a new file then just call that from both commands? Basically I have a command which is:...
Solution:
You can leverage this.store, just make sure you pas all the right arguments: ```ts import { Args, Command, type MessageCommand } from '@sapphire/framework'; import type { Message } from 'discord.js';...

error

Yesterday I had this error which was fixed by simply updating the framework
TypeError: Cannot read properties of undefined (reading 'parseConstructorPreConditionsRunIn')
TypeError: Cannot read properties of undefined (reading 'parseConstructorPreConditionsRunIn')
...
Solution:
This is the pitfall of not using either idHints https://www.sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/registering-chat-input-commands#idhints or using bulk overwrite https://www.sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/advanced/setting-global-behavior-when-not-identical So you should do either of those and in case of the former prune all your currently registered commands using whichever way to unregister commands. FWIW the logging when you first register a new command would’ve told you to add the ids to idHints....

Register a command on every guild

Hey, I am working on a bot, where I need to register some commands on every guild the bot is on. I cannot use global commands in that case. I was not able to find a straight forward in-build way to do that, so I wanted to ask, whether I missed something, or whether I have to implement that manually. I am still pretty new to sapphire, so if I need to do that manually, would be great if someone could give me food for thought....
Solution:
You'll pretty much have to end up handling registering yourself, which these methods make easier than doing it raw through the DiscordJS methods. As opposed to using the registerApplicationCommands in the command that is. Then as for how it will help, you can register the commands yourself to the guild in question when you receive a guildAdd event.

Intent question- paginatedmessage

Does paginated message require any intents or am I fine with just app command and bot scope?
Solution:
you need Guilds intent if you want the command to work in servers