Sapphire - Imagine a Framework

SIA

Sapphire - Imagine a Framework

Sapphire is a next-gen object-oriented Discord.js bot framework.

Join

sapphire-support

discordjs-support

old-sapphire-support

old-discordjs-support

old-application-commands-and-interactions

Preventing Commands in DMs

How do you prevent commands from being used in DMs? Message commands.
Solution:
Add runIn: 'GUILD_ANY' to your command options. This will only the command to be run in guild channels. If you want to specify a type of channel there are opttions for that

autoModerationActionExecution Event

Does Sapphire not emit the Discord.js autoModerationActionExecution event? The following code doesn't seem to trigger: autoModerationActionExecution.ts ```ts...
Solution:
Right just looked at Intents in case I was missing anything obvious and apparently AUTO_MODERATION_EXECUTION is a completely separate intent https://discord.com/developers/docs/topics/gateway#gateway-intents

Help canceling a command

Here the code I have for a simple reminder command.https://pastebin.com/crRSdjEn. It works but id like to be able to cancel a specific reminder / list the current active reminders. Can someone explain how the code is being run? My current thought would be that the class only has one instance but the async method can have multiple independent instances. How would I go about soring a list of all of the current reminders / canceling said reminders
Solution:
reminders like that won't work at all because you need to reply within 3 seconds and even if you defer then you need to reply within 15 minutes so a reminder could never be longer than that. You need to completely rework this and use a proper queuing/scheduling system, use an external database to store reminders and write some way to check if a reminder has expired and only then send it to the user.

What parameter do I pass to the run method in my GuildCreate listener?

Solution:
something like guild: public run(guild: Guild) {} ?

Problem with this.container.stores.get().get();

Code:
Solution:
The error means you're probably not running this code in a piece (listener, command, etc), so this.container doesn't exist. Instead, import container from @sapphire/framework directly.

InteractionCreate file

Can I easily create a listener for interactionCreate? I need it for some UI Abilities, and I am not sure if it overrides something...
Solution:
you can but you probably want to use interaction handlers the core even that trigger interaction handlers does barely anything really https://github.com/sapphiredev/framework/blob/main/src/listeners/CoreInteractionCreate.ts#L7...

How to Create Threads?

I dont get how to create threads programmatically. Please help

Command info

does sapphire have a built in command info funtions so we can get for example the aliases of a command?

args.pick("member")

using args.pick("member"), is it intended to get the member even if you just provide 1 letter of their username? if yes, is there any way to prevent it?
Solution:
Yes and no respectively. Can be added, make a GH issue. Sidenote that slash commands are overall better and you don't need custom args picking there....

why does this not work in sapphire

index.js ```js const { util } = require("./utils"); const { container } = require("@sapphire/framework"); ...
Solution:
That would be:
const util = require("./utils");
const util = require("./utils");
...

This code is not running on sapphire

```js const { Listener } = require("@sapphire/framework"); const { ActivityType } = require("discord.js"); const ms = require("ms"); ...
Solution:
figured it out, to anyone else that has this problem just add async before the run and also add this code before the async run(client) {} part ```js constructor(context, options) { super(context, {...

Bot stalls while registering commands

My bot was working fine yesterday after noticing the new Cog section of the documentation (really cool thank you it worked perfectly.) After I changed to the cog system I noticed the updates to the packages in Announcements. I ran npm upgrade and started receiving the channel errors noted in another thread which I was able to fix. The bot now just stalls when registering commands, any idea what I can change? The registrations match the documentation as far as I can tell. Log: https://pastebin.com/BrPAYDa3 Package.json: https://pastebin.com/rRQyYjWA register snippet: https://pastebin.com/xeiryjk8...

How to edit an Embed(Documentation isn't working)

Hi. Trying to make a discord bot that will send a message to a specific channel on startup. I have the message sent to the specific channel on startup, however, when I try to edit it a error is thrown saying message.edit is not a function. I am following the direct steps from the documentation and it is not working. Why and how do I fix this issue? ```ts...

Schdeduler SQS Options in index.ts

Where can I find what options I have to pass for the SQS Version of the Scheduled Task? I cant seem to find it in the guide

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?...