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?
better than the API ref docs I found
cause
I use the CLI to generate the classes
but the generated don't match the docs
Not really no but there isn't much to them either
as far as I can tell the ApplyOptions == constructor basically
https://sapphirejs.dev/docs/Documentation/api-utilities/modules/sapphire_decorators#applyoptions
There are examples. We can add more TSDoc comments if needed but I would think this suffices
Yes
(If your constructor only sets options)
Adding a function parameter to the applyOptions could remove even more and allow customizing the constructor easily, but also aren't there different options for commands vs listener vs events etc.?
oh I see it's typed in the options
obvs
either way, my comments are not indicative of my overall opinion, I really appreciate the framework guys
❤️
Adding a function parameter to the applyOptions could remove even more and allow customizing the constructor easilyNot possible with decorators. Especially not with ES spec ones in the future
but also aren't there different options for commands vs listener vs events etc.?That's what the generic type is for
first Discord TypeScript framework I actually like
Not possible as in, not possible in JavaScript
makes sense, you could have a boolean enable it and then check for an overridden function?
but at that point I guess
why not just have the users make their own
Constructor? Also not possible. Decorators are very restrictive.
https://github.com/sapphiredev/utilities/blob/main/packages/decorators/src/piece-decorators.ts#L52-L62 this is all that you can do and nothing more. As in, create a new instance and pass some options to it.
GitHub
utilities/packages/decorators/src/piece-decorators.ts at main · sap...
Common JavaScript utilities for Sapphire Projects. Contribute to sapphiredev/utilities development by creating an account on GitHub.
so something like this is irrelevant?
genuinely asking, haven't messed with decorators beyond this
Maybe the ES decorator spec will get more features in the future but that'll be many years
yeah fair
I did really like what DiscordX did with their decorators for buttons and stuff
Those are method decorators not class decorators. They're completely separate spec. Sapphire exports a few of those too.
they did
@ButtonInteraction({ id: "someCustomId" })
with your function handler below itThe reason we don't have many is because sapphire aims to be both JS and TS which is also why the decorators are in a separate package
ah understood
makes sense, I guess I feel that with Discord.js your real target is TS but I understand
Once decorators are in Node LTS spec so TS doesn't need to output tslib.__decorate code then we can move them to the core.
But God knows when that happens
copy that, makes sense
Probably not before Node 26... Or something like that
I am working on a discord bot that has privacy permissions and stuff and indexes questions for AI support to provide first round support for common questions
my job is in AI, so I can do that part incredibly well, do you think it's something I should try to just give to answer overflow?
cause I'm basically doing the same thing just for a different reason
it worked perfectly in python but single threaded killed me on it
so had to switch the bot to TS
I can't really vouch for or against @Answer Overflow. It's great for marking answers but I'm not sure how much functionality we get out of it beyond that. I have no idea how many,if anyone, uses the dashboard to search for answers before asking their question. Or search other forum posts for that matter. I know @Rhys intends to add more features, for example he mentioned using AI to give possible solutions to people once, however he also mentioned that wouldn't be a free feature and I don't know if we can afford paying for premium bot features because we get basically no funding.
I mean, so
I have a few open source communities I plan on funding
FYI JavaScript is ultimately still single threaded, but the event loop (and existence of worker threads) make it seem multi threaded.
for data and for my own thing
I mean it's less about that
and more about the fact that it's real async, and not some bullshit thing made up to make it work
cause Python kept running sub-event-loops and then they wouldn't quit and everything would take 2-3 minutes for basic things
thank you