sapphire-support
discordjs-support
old-sapphire-support
old-discordjs-support
old-application-commands-and-interactions
Failure Handling With Listeners.
This is more a design/architecture question. Just need more input.
So, a few of the commands I am writing for my bot are getting… complicated. By that I mean, database state is being updated, which leads to server categories being updated, and channels being updated, etc…So, instead of putting all the logic in my command class, I decided to go the event emitter route and
this.container.client.emit()
route and move the server channel/category/role updating to a listener that just responds to the custom event I emitted.
Something that crosses my mind though is how to handle if one of the listeners fail for whatever reason. ...Solution:
There's retry package by sapphire which can ease your retry attempts.
But you have to manually handle the errors & retry attempts...
Running Async Code in Precinditions
I didn’t see this in the docs. But, is it possible to run async code in preconditions?
TLDR: I need to load a “guild configuration” from my database, which contains the ID of a role that the caller must (in the server) to be allowed to execute some command.
Long question is, users (server owners) of my bot must run a “setup” command, which will create a “GuildProfile” for their server before they are allowed to use any of the other commands. In my precondition, what I want to do is get the “GuildProfile” for the server and see if the caller of the command has the role specified in that profile. If so,
return this.ok()
. Otherwise, return this.error()
....Solution:
I’m blind. Yes you can. Just found it in the docs. lol
Buttons Interactions
Hello fellows, I have some questions.
I'm a developer with experience with jda-ktx and JDA, I'm not great with shappire, I'm trying to learn it because it is really fast to boot up and does all of the things in milliseconds compared to the java one.
My question is, I have many embeds with buttons, they should modify the embed for the user that created the embed, but I have no idea how cold I do that....
Solution:
seems like my embed chages status
Getting Data from .env File
I created a new Sapphire app using the CLI. I am using swc. And, I want to ask how do access env variables in my bot? The project contains a
src/.env
file . So, naturally, I thought to put my discord token there and access it in my src/index.ts
file as follows.
```ts
const main = async () => {
try {
client.logger.info('Logging in');...Solution:
which is why i was saying to try
export const rootDir = join(__dirname, '..', '..', '..');
Testing and Sapphire/discord.js
Heya.
I'm new to Sapphire and Discord, but not new to JavaScript or coding in general. I'd love some hints/guidance on how to structure a bot to be testable and/or hints about mocking discord messages etc in a maintainable manner or pointers to publicly available bot codebases which have useful unit and/or integration tests.
Longer intro/problem background:...
Solution:
Unit testing Discord bot's has been a topic that's been discussed on and off in the DiscordJS community and the short answer has always been: just don't bother trying. It's not worth the effort. Mocking calls to the Discord API without a full blown Discord API mocking framework is nigh on impossible. The consensus has always been to extract the code that you want to test and test it separately without the scope of Discord stuff.
please help
we need help with a non respondent monitor and we have tried unplugging and changing the cords PLEASE HELP
Hello ,I need some Help about listeners in sapphire framework
any one have a working example of ("guildMemberAdd") , a bot that welcome user when they join the server .
The problem is like it can't detect that event , i do not know way...
Solution:
you're assigning the event GUILD_MEMBER_AVAILABLE, that's a different event from guildMemberAdd https://discord.js.org/docs/packages/discord.js/14.14.1/Client:Class#guildMemberAdd
Typescript error in @ApplyOptions
```ts
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';
import type { Message } from 'discord.js';
...
Solution:
Enable experimental decorators thingy in tsconfig
Is there events listing like discord.js does?
Just like in the screenshot, discord.js has listed out all events .
So where I can find the same for Sapphirejs?
Some of the listeners have multiple args, so I would like to see them all at once, just like this one: https://discord.js.org/docs/packages/discord.js/14.14.1/Client:Class#autoModerationRuleUpdate...
Solution:
you'll have to reference the source code where they are emitted (use search to find that). We currently do not have a way to automatically generate a list of events.
making a !help command. where do i get the commands from?
im trying to make a help command since I've started learning about paginated messages, but where would I get these commands from?
Solution:
There are several ways to get the list of all commands, depending on the context of your current code. The following are the different methods:
Inside another command:
...
this.store // Store<Command> extends Collection<Command> extends Map<Command>
this.store // Store<Command> extends Collection<Command> extends Map<Command>
this.error()
Is there any way of using
this.error()
but not trigger messageCommandDenied
? This is because on the messageCommandDenied
event I made it so it deletes the message if there's no error message, but in some cases I don't want to delete the message and instead do nothingThrowing errors in commands/subcommands
Just curious if there is a way to throw an error in an application command/subcommand and have it handled by the
chatInputCommandDenied
listener, similar to how preconditions work. Some kind of this.error
that can be sent and handled by the listener. Does this exist or can I write something to do that?Dynamic subcommand methods
Hey, i am creating some subcommands that basically have the same runner method, but i would wanna know which subcommand is being ran on that runner method, so i looked at the docs and i found the message context but it only returns commandName and not the subcommand or the group.
Solution:
well i have multiple subcommands that follow the same logic, but they are all different entities. and so instead of creating multiple methods and assigning them i would like to attach a single method to all of them since they follow the same logic, except they make the database entry according to which subcmd was ran, i know i can use a utility method to just override all of the extra methods i can create, but i don't wanna do that it would be better if i can just attach one single method and ge...
How do i use "separators" command in sapphire?
Hi! Im new at sapphire/framework, i was reading the docs and seeing there is a
separators
options at Command
my question is, how do i use the separators
command option and how to get the key from it?Solution:
You only customize the separators option if you have a very specific niche use case for customizing it. It is part of Options and defaults to one of
=
or :
. If you want to know the current value (which will be ['=', ':']
by default) you can use this.options.separators
Limit command to specified roles?
I honestly haven't done this in a while (not since pre-application commands) and am new to using Sapphire. Looking to restrict a command to only be visible/usable by the server's owner and any roles they define. How is this best handled with Sapphire and application commands? The bot in question has a database to store roles if that's needed.
Using TypeScript, here's a basic command I wrote that I want to restrict as described:
```ts
// commands/example.ts...
Solution:
You'll have to write and handle your own precondition https://sapphirejs.dev/docs/Guide/preconditions/what-are-preconditions
How to reference client in main file?
I am trying to get
<Client>.users
from the index.ts but I am unsure as to how I would get around to doing that..Solution:
if youre using sapphire, you can do
this.container.client
or import the container from the framework and then container.client
List registered commands and listeners
Hi, i love working with sapphire it's amazing.
I'm just wondering is there a way to obtain some sort of array or map of registered/loaded commands and listeners ?
Appreciate sincerely all the answers...
Solution:
There are several ways to get the list of all commands, depending on the context of your current code. The following are the different methods:
Inside another command:
...
this.store // Store<Command> extends Collection<Command> extends Map<Command>
this.store // Store<Command> extends Collection<Command> extends Map<Command>
Cannot find module
Anyone know what I need to install? (Ubuntu 22, image attached)
Solution:
https://github.com/nodejs/node-gyp#on-linux
though
sudo apt install build-essential
should be the command you need...Module augmentation does not work
I recently updated my project with the latest versions of typescript and @sapphire/framework, and then I run into the problem that augmenting typing no longer works.
I thought the problem would be pnpm, I even tried with the .npmrc configuration file "shamefully-hoist=true" but I'm still trying with yarn and the same thing happens, I don't know what to do.
These are the versions I am using and my tsconfig file....
Solution:
normally module augments should work just fine if everything is done right though. The last time I had difficulties was when I had incorrectly published some package (i think it was pieces) where it was missing some files in dist. Maybe check that out for your own packages? Check the files array and check the dist?