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
when a guild user runs this command, is the support channel per-command instance or per bot?
Solution:Jump to 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
44 Replies
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
The method on a command is called on every run
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
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.
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?
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
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...
I like that, makes sense, yeah I just think
like I was using DiscordX
I don't know nanostores so I cant answer that but it's probably unnecessary overhead. Just so
export myMap = new Map()
somewhere.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?
Overhead if you ask me like I said
Just get and set map entries
oh also
are there better docs for the decorators?
Never overcomplicate what can be done easily is my take
yeah fair enough
I like great systems 😄
hence why I like Sapphire
Better than what exactly?