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

Profile Color Member

hi, can someone tell me how to retrieve the primary color code of the user profile and not banner ?

Subcommand not registering

Hello, I was not really sure whether I should post this in #discordjs-support or #sapphire-support, but since it's an issue regarding subcommand registration, I decided to post it here! I'm kinda new to all of this and I just made a new bot. I wanted to create a /channels command (here is the code: https://hastebin.skyra.pw/cezeqivufo.less) but when I try to run the bot, I get the following error: ``` 2024-09-20 17:40:06 - ERROR - ApplicationCommandRegistry[channels] Failed to register application command with name "channels" DiscordAPIError[50035]: Invalid Form Body...
Solution:
I just replaced the new SlashCommandBuilder() with (builder) => builder and now it works! ```ts // Pretty much like this: export class ChannelsCommand extends Subcommand { public override registerApplicationCommands(registry: ChatInputCommand.Registry) {...

Slash Commands Embeds

Im currently working on a discord bot and i am on the last step which is making the commands. i need help though. I wanna know if i am able to run the command and the bot responds in an embed message

Help with message deletion

I am currently implementing message deletion logging into my bot to replace another bot that doesn't log attachments upon deletion. I assume that the DAPI passes attachment information along with the rest of the Message object when messages are deleted. However, referencing the attachment via URL wouldn't work because, well, you can't reference a url that doesn't exist anymore. Is there a way to retrieve the raw image data or get a Stream from the Attachment object that is returned with Message#...
Solution:
u can actually use the url because they dont get deleted immediately like the message. i cant remember how long it takes for the attachment url to get deleted though

How does one check if a specific user was mentioned in a message?

I was thinking it would be something along the lines of MessageMentions#members.has('UserID'), is this correct?

Typing - Question message

So I have this and I am confused entirely what the reason is. Import is
import { EmbedBuilder, Guild, Message, User } from 'discord.js';
import { EmbedBuilder, Guild, Message, User } from 'discord.js';
...
Solution:
Okay so using npm instead of yarn worked, I was on latest v4 but it may have been my yarn lock file
No description

Keep getting "Shard 0 is reconnecting..." errors

My bot keeps getting "Shard 0 is reconnecting..." errors every couple of hours and I'm not sure why. Running discord.js 14.15.2.
No description

Question about developing in TypeScript

My bot which is used by 10,000 members is fully written in Sapphire for JavaScript. I was thinking about converting it to TypeScript to make the code better, and safer. I wanted to ask, from your experience, does using TypeScript make a difference in how you code? does it make a difference in the performance? Is it worth it? Cheers!...

Is there a way to make the bot press a button component within a message

Wondering if there's a way to simulate a button press on a message (particularly a message that wasn't sent by the bot).

getChannel does not exist for interaction.options

Howdy, I'm trying to get a text channel from a command channel option, but I'm getting the error that 'getChannel' property doesn't exist even though it appears as a method in the docs and I've seen it in other people's code. I'm using the typescript complete example bot as a base. Npm ls returns discord.js 14.14.1
ts:32:51 - error TS2339: Property 'getChannel' does not exist on type 'Omit<CommandInteractionOptionResolver<CacheType>, "getMessage" | "getFocused" | "getMentionable" | "getRole" | "getAttachment" | ... 6 more ... | "getSubcommand">'.

const channelOption = interaction.options.getChannel('channel', true);
ts:32:51 - error TS2339: Property 'getChannel' does not exist on type 'Omit<CommandInteractionOptionResolver<CacheType>, "getMessage" | "getFocused" | "getMentionable" | "getRole" | "getAttachment" | ... 6 more ... | "getSubcommand">'.

const channelOption = interaction.options.getChannel('channel', true);
...
Solution:
Type it as a ChatInputCommandInteraction. Your current type is ambiguous as to wether it's chat input or context menu.

Editing a message deletes it

To explain my system. I have a music bot that some events trigger certain message edits. Upon a user playing a song, an embed with buttons get sent (pic 1) this message gets stored within Guild class I extended with types. upon clicking one of the buttons, the message gets edited with new information. For example if someone pauses the song the button changes to another button. But the problem with that is that, upon editing the message. It deletes it. Pictures besides 1st one, show the code pretty much. 2nd pic shows how i store the message and what happens when a track starts playing 3rd pic shows whath what happens when player gets resumed (same thing happens with pausing or any event that edits the message stored)...
No description

MongoDB Discord.JS (Only saving to 1 profile)

```js const { Client, Message } = require('discord.js'); const calculateLevelXp = require('./calculateLevelXp'); const UserProfile = require('./userProfile.js'); const cooldowns = new Set();...

Help fetching users

I didn't know if this was a sapphire or d.js issue but this line of code im using to fetch the users just isn't returning the right amount of users with the specific role. I've tried just getting all the users then filtering them with the role and it also doesn't work correctly ```ts const supportRoleId = interaction.options.getRole('role', true).id const logChannelId = interaction.options.getChannel('log-channel', true).id...

role not being given

logs saying they were removed, but they weren't

Button error

anybody knows why this is happening? So I have a ticketing system that just stopped working now, for some ungodly reason, closing the ticket takes ages, it will not close it and then error out.
2024-03-30 20:58:07 - ERROR - Encountered error while handling an interaction handler run method for interaction-handler "ticketClose" at path "/home/container/src/interaction-handlers/ticket/ticketClose.js" TypeError: Cannot read properties of null (reading 'delete')
2024-03-30 20:58:07 - ERROR - Encountered error while handling an interaction handler run method for interaction-handler "ticketClose" at path "/home/container/src/interaction-handlers/ticket/ticketClose.js" TypeError: Cannot read properties of null (reading 'delete')
...

Slash Command Error

`node:events:492 throw er; // Unhandled 'error' event ^ TypeError: interaction.isChatInputCommand is not a function...

Invalid Token Error

How do I fix this error: ```js const invalidToken = new DiscordjsError(ErrorCodes.TokenInvalid); ^ Error [TokenInvalid]: An invalid token was provided....
Solution:
you should be using "client.on" or "client.once" for events

Apply Overwrites in a voicechannel

How do i apply overrides after a channel was created?
No description

Create a category and a channel in the category

I try to create a Category and a channel in it, somehow it dont accept the category as a parent ```ts static async createAndRegisterVCGenerator(guild: Guild): Promise<VoiceChannel> {...
Solution:
Review the documentation provided by DiscordJS. Your syntax is wrong. https://discord.js.org/docs/packages/discord.js/14.14.1/GuildChannelManager:Class#create
No description

Bot not starting in VPS

My bot works great on my PC but on my VPS it is not loading.
Solution:
I had to contact my VPS provider (aws) and ask them to give me a new IP address, works like a charm now
No description
Next