Is there a way to make an Event (registerApplicationCommands) 'wait' before triggering?
Okay so I created a handler named
unregisterer.js
I'm calling it in another handler named bootstrap.js
bootstrap.js
is then imported into index.js
then called as such await handlers()
on ready
event
I use a custom structure named SlashCommand
imported in every command file (to replace Command
of @sapphire/framework
): this only serves to prevent spamming registerApplicationCommands
in every single command file
meanwhile Command
is already called within the structure itself to serve it's purpose
The expected behavior is to first unregister all the Global commands, afterwards register them once again, acts as a reload for the existing commands
There's 3 types of different behaviors when booting up the bot in a row, I've embedded a video
192 Replies
Sounds like what you're really looking for is https://sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/advanced/registering-application-commands-outside-a-command
Sapphire Framework
Registering Application Commands outside a Command | Sapphire
You are able to register your application commands inside of their command class, but also outside of the class! Whether
that's not what I need
"The expected behavior is to first unregister all the Global commands, afterwards register them once again, acts as a reload for the existing commands"
Unregisterer.unregisterGlobalCommands()
is executed in applicationCommandRegistriesInitialising
when the event it's triggered
However structures/SlashCommands.js
will also proceed to register commands at the same time, I can't come up with a combo to make it "wait" to complete unregistering all older global commands
this is structures/SlashCommand.js
structure that I wrote to individually register each command without repasting the same code in every single command
and this is how I use SlashCommand
structure in my command files
not even sure if the way I wrote Unregisterer
func even works as intended 'cus I see duplicated list of commands, both global & guild registered are displayednot to mention, if I include a piece of code in
applicationCommandRegistriesInitialising
eventlistener, execution is delayed as console.log came late, async/await in this scenario serves 0 purpose, I might not be a master at js but frankly I'm on a stale like thishonestly you've kind of lost me... but to answer the question of
Is there a way to make an Event (registerApplicationCommands) 'wait' before triggering?afaik no. @vladdy?
take ur time to read this, I'm not expecting an immediate answer
I also noticed what the cause of the delay is however I still have doubts by the way I'm handling this
Outside the fact you should not do this (delete and recreate to update commands, use commands.set), why are you manually handling command registration and also telling sapphire what to do? It really sounds like all you need is to set the default method to bulkoverwrite, and setting the default guild ids somewhere before calling login and thats all
And the answer to the
wait for x before an event handler is ran
, the answer is no.does sapphire handle the deregistration of unexistent commands by itself?
If you use BulkOverwrite, yes
Otherwise no
BulkOverwrite tells sapphire "you handle the entire state of the applications commands, any external changes can be overwritten/removed"
Whereas the other modes tell sapphire to handle only what its told about
so is it fine if I do
registry.getDefaultBehaviorWhenNotIdentical(RegisterBehavior.BulkOverwrite);
in applicationCommandRegistriesInitialising
eventlistenerBulkoverwrite, and you call it before login
And not get
ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical
I see where my mistake was
thanks
which applies globally
:salute:
yeah but thing is I want to prevent global commands from being defined
lol
that's what
registry.setDefaultGuildIds(guilds);
is forSo then also call ApplicationCommandRegistries.setDefaultGuildIds before login too
ye xD
before login huh
ya
I'll import them as handlers before login then
thanks for the support
You dont need it to be a handler tbh
I just want to make the core file as clean as possible
yk
so I can rid of stuff like
unregisterer.js
and just directly use the BulkOverwrite
provided by sapphiremhm
I knew it had some automation but hell I read docs and I was this clueless
š
Just keep in mind that if you create a cmd outside sapphire, and then you start with Bulkoverwrite, that cmd will vanish
And the only commands that will stick are whatever is in the command registries
I'll give it a try rn and will give a feedback later
gotta write some code and start testing
a thing tho, if I want to turn off the
ApplicationCommandRegistry[command.name]
logs that popup when a new command is registered, seems like loadApplicationCommandRegistriesStatusListeners
set to false
can't do that by itself
Seems like ApplicationCommandRegistry.setDefaultGuildIds
is unrecognized as a function in my use case
Ima find another approachit does exist
show code
Not registry
I know it does exist
Registries
not that one
oh
ApplicationCommandRegistries
Registry is an instance per command
ah this is way better now
now there's only 2-3 things I need to do before I actually work on the commands
wait an hour to see if BulkOverwrite did the job and global commands get removed so no more 'duplicates'
its not an hour
second is to find out why Preconditions does not want to work
just refresh your client
restart the bot or wym
no, ctrl r in discord
oh I did that but still dupe earlier
I'll try quitting discord
and do both run?
obv not
p sure the one that doesn't run is the global command
check command ids i guess
this way?
naw
well
lol
log command.commandRegistry
or i think applicationCommandRegistry
ye applicationCommandRegistry
yee, that should show ids and all
nope, it's only a batch
no duplicates
hmm?
it must be my discord then
screenshot pls
..empty?
that..is not right
cus I'm console logging this before they're being registered
that's why it is empty
OH
let me log it after it's registered
sec
I got an event for that
yay its on the client showing it wrong
thank lord LMAO
wait what
š
that's what I said
give me 2 min I quit discord
yeah no sapphire handled it right, only shows the guild one, i was worried smth was fucking up XD
I came migrating over from raw commands
with raw commands I could do anything š
but decided few days ago it's time to move on...
so I did a LOT of trial & error with slash commands
obv sapphire framework cus Imo best
Realistically this should work, MIGHT have caching issues because discord but in the long term it'll be better (i'd assume)
If there's something that doesn't work as intended
Is that preconditions don't work with slash commands š at least for me
show the preconditions
oh
duh
yeah that will never work
its chatInputRun for slash cmds
shrug
run should handle it the same way
messageRun and contextMenuRun respectively
no?
Run doesn't exist in sapphire anymore for Preconditions and Commands
cus I also use run for commands and rest of the eventlisteners
then why does my thing work š wtf
Edited in more context
Commands and Preconditions use
<type>Run
because you might need diff handling for messages vs interactions
Listeners n such just use run tho
your cmd is also wrong, will never run without it being chatInputRunuh
I thought this was a client issue
š
:Confusion:
What sapphire version are you on
whatever gave me when I downloaded sapphire a few days ago, should be latest
,...unless it's not
Uh, we definitely set globals to empty array if commands are registered as guild only by def
Can you share more code, not just snippets pls
Is there a chance cus of my SlashCommand constructor
naw that looks fine
oh ok
Can you show your main file
and in bootstrap?
loadOverwrite is uh
Invalid
:KEKW:
š¦
no way
If I called it as a function it'd return undefined
what
Registry.setDefaultBehaviorWhenNotIdentical(Behavior.BulkOverwrite)
also drop async from that function, you dont need it
and it may prevent race conditions
XD
I love async
cus it creates me more problems to worry about
š
not if you have eslint/ts yell for promises not being handled
you've no idea how many times some devs raped me to always use it
š
async await is fine!
just gotta be careful with it
EYYY
btw one thing
this
Those log messages cannot be turned off for bulk, woops LOL
I'm gonna commit š¦
anyway
let me see if commands now dupe
Make an issue for it, we can make it an event
Like for normal registrations
In the end I just want it to customize the console
get my point?
I don't know what any other use would it serve
Use or make a logger and done
a logger to do what
It wont prevent it from logging
to override the default one
oh well
then you can also ignore specific messages
BUT
I don't know to use those
.
I did see it on ur docs tho
on github? sure
Yeah, bulk was added after that setting :OMEGALUL:, and we always wanted to print something so people knew that smth happened
too much to write for a feature request š
Just link this thread
Give it a good title and link this thread
Its fine XD
request: Add ApplicationCommandRegistries Event Listener
š¤·āāļøBulkOverwrite event listener
but yes
why not just create a generic event that listens to every subevent of that type of event
bc this was added later
:OMEGALUL:
š
But yeah just make the issue, I already know how to handle this
:kekGasm:
BulkOverwriteError before BulkOverwrite
yeah we only have an event for error, not info :OMEGALUL:
I mean
It works out
hey but it works now :thanksForFlying:
yes
It works so well I forgot to get back to testing
lol
Say, if I wanted to create an event listener for grabbing any sort of error that a command, a handler or an event listener may cause, does sapphire got any sort of integrity in that kind of exertise? Considering I had to use try/catch everywhere, engulfing everything within a function call I thought about it but it's bad practice Imo
yeah we have error events
ListenerError, CommandError (split by type of commands), etc
the issue with precondition still persists
even after I replaced
run
with chatInputRun
mmm does it get called?
and whats the file name of the precondition
developer.js
Is it case sensitive so it must match the precondition's class name?
tried console logging, it does not get triggered at all š¤·āāļø despite someone who isn't in that list using the commandyes
if you dont pass in a constructor with name: "", it takes by the file name
and case sensitive
bruh
I was wondering why was I getting the whole array instead of just options
the way it's stored š
I see, thanks
question tho but the relevant properties stored in the commands
is having name & description duped in
options
a bug or featurewdym
š
It's literally set to store things this way
uhhhhhh
is that this.options?
but i think its intended, that idk about LMAO
I want to get
this.options
yes but I had to do this.options.options
to reach it
š
cus duped information is stacked within the options
array
can I report this as an issuei think its intended
we already got
name
& description
on command itself
š¤·āāļøJust check when it was added and why
but iirc it was intended for smth
uh
well whatever
oh the core piece stores the options
Yeah this was intended, but you can extend the cmd class to store your commandOptions in a this.field
this.options.options
If anyone asks me, I'll tell them which framework I'm using
:kekw:just store this.commandOptions = options.options in your constructor
that works out too Ig
I made a handler for slash options, it works however I'm getting
Unknown interaction
every timethats bc if your precondition doesnt return ok, it will reject
and we emit an event for it
so you need to handle it
It's not the precondition
its a command denied event
you'll need to share code! :Prayge:
yes
otherwise cant help
sec
this is the testing command,
avatar.js
and is your chatInputRun called?
and I wrote allit on
SlashCommand
structure to register Slash Command otions as well
command works yes
even shows option to select user yes
and gets their pfp
but I still get at every interaction this
that usually means the response is slow, which is weird
this is the whole log
I am thinking but
perhaps
interactionCreate.js
is causing this issue? š¤·idk what that is
It's this
why
why
why
xD
are you trying to do what sapphire handles for you
š
I don't remember what I used this for
but Ig I don't need it
disable it and try again
yep
this was the cause
I removed it entirely
I come from a version of sapphire where I had to write allat
š
jeez how old of a version
god if I remember it's years ago
pre slash commands in general?
before slash command exist
that explains
XD
yeah sapphire handles alllllll of this
btw I dm'd u earlier
Ig u might not check ur dms often
oh i have message requests LOL
yo sorry to bother again
does sapphire provide a way to handle options, suboptions, choices & rest?
wdym
In slash commands its only what discord provides
as u can see
For subcommands we have a plugin to make handling it easier
But otherwise no
with my method I can register up to 1 options, I could spam this to check for more suboptions, choices or menus
but frankly I think that what I'm ab to do is bad practice
what I need is for suboptions
So you mean you want subcommands and choices?
I want to handle those situations for future cases
I'd suggest reading up on Discord's system first, then looking into the builders methods for it
But this is why we have a registerApplicationCommands function per command
You'd probably be better off replacing the register methods on classes that need options
hm
I'll see what I can do on my end