Je Suis Un Ami
Explore posts from serversSIASapphire - Imagine a framework
•Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
Is there a way to extend the existing logger within Sapphire?
I saw that in the logger argument of the client constructor I can pass an instance of
ILogger
. So, I thought I could just extend the Logger
class from @sapphire/framework
and pass that to the instance argument.
Doesn’t seem to work. It’s not formatting my logs. Seems to stick to the default logger. Are there any other options?
I am kind of looking for a way to just work with the existing logger instead of creating an entirely new plugin. The only real change I am making is formatting log messages like so: [context]: message
, where context shows where the log is coming from (I.e. MyCommand.chatInputRun`. And message is the normal log message.
I could just pass a formatting function to the current logger. But this is a very error-prone solution.
Thanks in advance.16 replies
SIASapphire - Imagine a framework
•Created by Je Suis Un Ami on 3/5/2024 in #sapphire-support
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.
Does Sapphire provide an option to automatically retry listeners if they fail? Or am I gonna need to manually handle that somehow?15 replies
SIASapphire - Imagine a framework
•Created by Je Suis Un Ami on 3/3/2024 in #sapphire-support
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()
.
However, it doesn’t look like I can run async code in preconditions. So, is there a way to do so? Or am I gonna need to perform this check in the *Run()
method of my command?4 replies
SIASapphire - Imagine a framework
•Created by Je Suis Un Ami on 3/2/2024 in #sapphire-support
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.
However, running this throws an error : Error [TokenInvalid]: An invalid token was provided.
. However, it runs if I pass the discord token as a string literal to the client.login()
method. So, this tells me the src/.env
file isn't getting included in the compiled source code. And, upon reviewing the outputted 'dist
folder, it appears this is the case.
How would I fix this? Or, is there a different way I am supposed to access environment variables?128 replies