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

Will using the new plugin-utilities-store enable HMR for this Helper files?

As stated in the title: If i add some functions to the util store will they be reloaded on change with the hmr plugin?
Solution:
Yes, since they are pieces

"Send" does not exist on type "channel"

Hi. Trying to make a discord bot that will send a message to a specific channel on startup. I try the method of caching the channel and then sending the message. An error is thrown saying "Send" does not exist on type "channel". ```ts...
Solution:
Solution(For Future People trying to solve this issue) ```ts const channel = await client.channels.fetch("1076251641625456700"); if(channel?.isTextBased() ) {...

How can I create a listener for @discordjs/voice states?

Title kinda explains itself lol, but how can I convert things like ```javascript const { VoiceConnectionStatus, AudioPlayerStatus } = require('@discordjs/voice'); connection.on(VoiceConnectionStatus.Ready, (oldState, newState) => { console.log('Connection is in the Ready state!');...
Solution:
Nevermind I found my answer somewhere else

@sapphire/shapeshift (?) crashes bot when trying to send embed with description exceeding 4096 chars

hi, so I have a message cmd which shows info on a github user in a nice embed. when bot sends the info embed, it also has a button attached to it to help fetch publicly available events for gh user if pressed. I process all interactions on this button through message.createMessageComponentCollector method. I do all this inside messageRun method. The bot send the info embed with button just fine, but when button is pressed to fetch the public events of a github user, it basically crashes bot even when I wrap my whole login inside messageRun in a try-catch block, it still crashes bot because sometimes embed description is set to long string of 4096+ chars which the button interaction would send. The full error I get is here: https://gist.github.com/o-wo/c53217fdcca9d547bba353213a865e4d I cant figure out what I did wrong, I only want to understand what is crashing the bot: shapeshift or sapphire or its d.js issue? and why it is straight up crashing the bot? even when I put whole code logic inside try catch block. Since error log I see in console mentions shapeshift in many places, it suspects me to believe its causing this? hence I put question mark in post title. apologies for any misunderstanding on my part. If any experts can point a novice like me in right direction or help me understand its cause, your kindness would be immensely appreciated. 🙏🏽...
Solution:
Well you correctly identifiet that the error is coming from Shapeshift and the reason is that the string exceeds the maximum length of 4096. What you can do to circumvent this is use the cutText https://www.sapphirejs.dev/docs/Documentation/api-utilities/modules/utilities_src#cuttext method from @sapphire/utilities to ensure it doesn't exceed that length. Use 4096 for the number, or if you have other text in the embed then a lower amount. Discord embeds as a whole cannot exceed 4096 (this is description + title + fields, etc) That said, I'm surprised this is crashing your entire bot. At best it should land in the error listener. Are you sure you haven't implemented a re-throwing mechanism in your own error or messageError listener?...

uninstlling @sapphire

How do i uninstall this so that it stops loading as a dependency. I've run
npm uninstall @sapphire/framework
npm uninstall @sapphire/framework
multiple times and everytime i run
npm i
npm i
@sapphire is always in the list of node_modules.....

Manual task not executing

Hiya, One of the tasks for a temp ban doesn't seem to execute after the amount of time I specified in the command. I've played around with other tasks that have worked before and still do work, updated the modules that are related to this and also delete the redis database after. I've also looked around and I don't think it's related to this: https://discord.com/channels/737141877803057244/1074660009117499413 because other pattern tasks have been working for a while, and I've gotten other called tasks to execute after 9 seconds....
Solution:
I feel slightly silly with how simple of a problem/fix it was. I used event listeners to find out that tempBan was not found but the name of the file was tempban.ts, so it wouldn't run because the file name was all lowercase.

Registering commands and other paths

Hi guys! I'm having some troubles. When I use sapphire new, everything works as intended. The commands in the commands directory are registered properly. However, if I do not use sapphire new and try to add it to an existing project, without sapphire init, it doesn't register the commands. After looking into it, and logging the stores, I see that the paths should be C:/.../myProject/bin/commands, but the path is showing C:/.../myProject/commands. Even if I copy the .sapphirerc.json from the other working one....
Solution:
Topmost big red block: https://www.sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire Configure the main property in your package.json correctly...

Is it possible to update slash command string options every time the command is ran?

This command acquires data from Firebase and use it as string choices. However, data from Firebase is not constant and will change from the moment the slash command is registered.
Solution:
1. No, commands are registered at the Discord API level. No this is not a Sapphire or DiscordJS limitation, it just just how the Discord API handles slash commands. 2. Instead of pre-defining options you should use auto completion which can be filled dynamically, for example try using /pokedex from @Dragonite which also queries an API for its options....

ts-node giving issues with Sapphire (edit: DO NOT USE TS-NODE)

Solution:
TL;DR: Do not use ts-node, use tsc-watch instead. We very strongly discourage using ts-node because it was never meant to be used for bots. ts-node is designed for REPL purposes. That's short for Read Eval Print Loop....

scheduled jobs randomly stop working

Hello! I have three different scheduled jobs at different intervals. 1 minute 10 minutes 2 minutes...

sharding

hey so i want to use discord hybrid sharding i wanted to ask if there will be issues with using it with your libary like does your libary shard or not
Solution:
sapphire is built on top of discord.js and since discord.js support sharding so sapphire with support it too

port 4000 on cluster

so my bot is in more than 8k servers and it requires clustering so when i start the bot i get this Error: listen EADDRINUSE: address already in use :::4000 i dont want to use any ports at all...
Solution:
In your API options in client options set automaticallyConnect to false and then in some event like ready or similar start it just once and on one shard by calling client.server.start

How to defer reply with Sapphirejs

Yes I know, Sapphire doesn't have this feature built-in, so I was wondering how to do it without it?
Solution:
Sapphire is built on top of discordjs. You still use discordjs methods and methodologies. That is to say, the same way you do as with discordjs.

Default preconditions

I'd like to create a check for all commands before they are run, and I'd like an alternative to pasting a precondition in every command file. Is there another way I can, for example, intercept the interactionCreate event or something?
Solution:
If it's a custom precondition that you wrote yourself add the position option to any value (the higher the value the higher the priority) and it'll turn into a global precondition.

Commands not responding to defaultPrefix

I've setup the defaultPrefix to "!": ``` const client: SapphireClient = new SapphireClient({ "intents": [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages], "loadMessageCommandListeners": true,...
Solution:
you need MessageContent intent

ts not compiling well

I don't know if it's a discord.js/sapphire issue or just a compiling issue, but when compiling normally or with ts-node, bot doesn't run at all but instead shows an error on all command files (picture below) and I dont know how to fix it
Solution:
update your dependencies. Permissions is removed in DJS v14, you need matching versions of all the Sapphire dependencies (their latest versions)

How To Use The Enum Arg?

Hello, I'm trying to use the enum arg in order to accept only one of two strings. How does one pass in the acceptable options for the enum? Could someone provide me with an example?...
Solution:
args.<method>('enum', { enum: ['one', 'two'] })

Let's users have custom folders for pieces

As the title states, I think sapphire should let people place commands, listeners and interaction handlers...etc( all pieces ) in custom folders. Maybe sapphire should let people set the paths of those pieces in SapphireClientOptions.
Solution:
Already possible. You can register a path for a store. If it is for a single store then use ```ts <this>.container.stores.get('mystore').registerPath('path/to/the/folder/here')...