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
TTeixeira4/29/2024

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).
FFlash4/22/2024

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.
SStealth4/22/2024

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
EEdge4/14/2024

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();...
LGLynx Gian4/7/2024

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...
Ddried3/31/2024

role not being given

logs saying they were removed, but they weren't
T./Ticker3/30/2024

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')
...
Ddried3/30/2024

Slash Command Error

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

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
FFabi3/23/2024

Apply Overwrites in a voicechannel

How do i apply overrides after a channel was created?
No description
FFabi3/18/2024

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
T./Ticker3/16/2024

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
Ppush03/4/2024

commands doesnt work

client.commands = new Collection(); const commandFiles = fs.readdirSync('/root/eye/Eye/Eye/commands/').filter(file => file.endsWith('.js')); for (const file of commandFiles) {...
RHRIZE Hobberz2/29/2024

/twitchadd (name) (link)

name = choice name link = choice value...
No description
KKitomanari2/17/2024

A bunch of errors from discord.js's index.d.ts file when compiling

djs version: latest (14.14.1) If needed, I can send my ts-config here. Some notes: - Adding skipLibCheck doesn't help....
Solution:
No more needed, I solved my problem myself, thanks for your attention. The issue was that my TS compiler was outdated (4.9.5) so it didn't fit for the new djs. I updated it to the latest version (5.3.3.) and it solved the issue....
No description
GGangsterhood1012/16/2024

help

keep getting this error not sure how to fix ```RuntimeError: abort(TypeError: fetch failed). Build with -s ASSERTIONS=1 for more info. at process.abort (C:\Users\thoma\Desktop\Emost-Bot-master\node_modules\bumblebee-hotword-node\lib\porcupine-v1.9\pv_porcupine.js:486:11) at process.emit (node:events:519:28) at emit (node:internal/process/promises:150:20)...
RRavelt2/13/2024

User object roles

If a user uses a slash command, is there a guarantee the member object I receive in the handler would be the latest update of that member? I had assumed that would be the case but I'm having behaviour that would suggest the member object I receive does not have the latest up to date information on what roles the user has.
Solution:
Turned out to be user error lol
Qqvgk2/1/2024

Getting the deleter of a deleted message

Hi, I'm trying to get the deleter of a deleted message using .fetchAuditLogs() and .entries.first(), but sometimes they don't work... If I were to create a message and delete it, it would show me as the deleter. If I then created a message and then someone else deleted it, it would still show me as the deleter. Then, eventually it would switch and then always show the other person as the deleter. (I tried asking in the DiscordJS server but they always say I'm wrong and don't actually help 😔)...
JPJuan Pablo1/31/2024

Make a button executable only by the command executer

Hello, I want to make a button only executable only by the person who ran it. For example, if person A runs command fuzz only they are allowed to click on button B I thought this would work it seems to split out [ERROR] Encountered error while handling an interaction handler run method for interaction-handler "bankButton" at path "C:\Users\Isidr\Documents\GitHub\cobaltia\cobaltia\dist\interaction-handlers\buttons\bankButton.js" TypeError: Cannot read properties of undefined (reading 'id')...
Solution:
I would add userId to the button custom id and regex match it. One way it says you can do it in guide iirc
T./Ticker1/1/2024

anyone know how to make bot seem without a status (not online but not offline)

like for @Iriss
Solution:
By not using libraries like discord.js, you'd use a HTTP server instead of connecting to a websocket. @Iriss uses @skyra/http-framework, but discord-interactions is also an option, and the one that's recommended in Discord.js
Next