Scope of Command Classes?

Hi just curious, what's the scope of command classes? Is a class created each time you run the command, or
export class ConfigCommand extends Command {
supportChannel: Channel | null = null;
settingsEmbed: EmbedBuilder | null = null;
permittedRoles: string[] = [];
export class ConfigCommand extends Command {
supportChannel: Channel | null = null;
settingsEmbed: EmbedBuilder | null = null;
permittedRoles: string[] = [];
when a guild user runs this command, is the support channel per-command instance or per bot?
Solution:
An instance is created before the bot logs in and afterwards that same instance is always referenced. Thank god because otherwise perf would be dogshit
Jump to solution
44 Replies
Solution
Favna
Favna6mo ago
An instance is created before the bot logs in and afterwards that same instance is always referenced. Thank god because otherwise perf would be dogshit
Favna
Favna6mo ago
The method on a command is called on every run
ZachHandley
ZachHandley6mo ago
I figured yeah, in that case, what's the best way to deal with having data between command and interactions? e.g. in my config command they set up which channel is for support, roles, etc. and I could keep it in my DB the whole time and just update it with interactions if I need to I could create a class with the embed and data maybe and just make a new instance per command keyed by the user's ID or guild's ID
Favna
Favna6mo ago
If you can fit it down to 80 or so string characters then customId field. Otherwise some temporary storage like an in memory Map or a Redis database with keys being a combination of commandId-guildId-interactionId or such and values whatever you want to pass.
ZachHandley
ZachHandley6mo ago
ah damn okay, have you guys considered adding any kind of storage or state management to SapphireJs? Nanostores probably works with it I'd imagine?
Favna
Favna6mo ago
Regarding the former I do this for @Dragonite https://github.com/favware/dragonite/blob/main/src/lib/util/utils.ts
GitHub
dragonite/src/lib/util/utils.ts at main · favware/dragonite
A Pokémon information Discord bot built around Discord Interactions - favware/dragonite
Favna
Favna6mo ago
Funny you mention it because @kyra 🩵🩷🤍🩷🩵 has abandoned it twice 1. https://github.com/sapphiredev/utilities/pull/118 2. https://github.com/sapphiredev/utilities/pull/663
GitHub
feat: added string-store by kyranet · Pull Request #118 · sapphired...
TODO Dynamically increase size on size-unknown payloads. Add tests, lots of tests Does this thing even work? Endianness is a pain.
GitHub
feat(bit-array): initial commit by kyranet · Pull Request #663 · sa...
This is a dependency for @sapphire/string-store's unaligned (and more compact) data storage, based on TypedArray's API, but using bits instead of bytes. Pending to add the missing code, and...
ZachHandley
ZachHandley6mo ago
I like that, makes sense, yeah I just think like I was using DiscordX
Favna
Favna6mo ago
I don't know nanostores so I cant answer that but it's probably unnecessary overhead. Just so export myMap = new Map() somewhere.
ZachHandley
ZachHandley6mo ago
and a large part of why it was useful was because even though the commands were static, the interactions and stuff were in the same class, though I hated their docs and everything else about it so the separation of concerns is dope, but also it makes it harder to pass info because everything is so separated, so a storage seems like a natural way to pass things together plus in theory wouldn't stores with Nanostores or something reactive be the best idea so you can just subscribe to the value?
Favna
Favna6mo ago
Overhead if you ask me like I said Just get and set map entries
ZachHandley
ZachHandley6mo ago
oh also are there better docs for the decorators?
Favna
Favna6mo ago
Never overcomplicate what can be done easily is my take
ZachHandley
ZachHandley6mo ago
yeah fair enough I like great systems 😄 hence why I like Sapphire
Favna
Favna6mo ago
Better than what exactly?
Want results from more Discord servers?
Add your server