Custom slash commands registration

Infos: https://discord.com/channels/737141877803057244/737142209639350343/1240606406290178078µ Hey, so im doing this to create some custom slash commands. So the question is, does sapphire, have kind of collection or something i can add the command to it? so it don't get removed
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
No description
Solution:
Only if you use bulk overwrite
Jump to solution
115 Replies
UndiedGFX
UndiedGFX8mo ago
so it don't get removed
it does not get removed
Youssef
YoussefOP8mo ago
it does
kyra
kyra8mo ago
If you're using BulkOverwrite, yes If you use Overwrite or any other strategy, it shouldn't
Youssef
YoussefOP8mo ago
im talking about this command, btw
No description
Youssef
YoussefOP8mo ago
not the command file
UndiedGFX
UndiedGFX8mo ago
you should not create commands like that that is anti-sapphire
Youssef
YoussefOP8mo ago
Im not registering the other commands like this.
kyra
kyra8mo ago
Undied please, there are reasons why this is made, namely for hoisting custom commands/tags as guild commands (Which is a feature I'd like in one of my bots, which makes me understand the need)
Youssef
YoussefOP8mo ago
exactly, thanks for understanding
UndiedGFX
UndiedGFX8mo ago
if a command is created in a guild, it shouldnt be removed after logout right?
Youssef
YoussefOP8mo ago
it's for tags, every tag i want it as a comand it's not this the problem, the problem is the command created by me is not gonna be saved to the collection or the thing that use sapphire to store commands
kyra
kyra8mo ago
What I said about the strategy is because it should in theory not remove the commands unless you're using BulkOverwrite, which replaces the commands with those Sapphire can read Oh, that
UndiedGFX
UndiedGFX8mo ago
store in a database
kyra
kyra8mo ago
Why store in a database when Discord gives it to us + we fetch it anyways
kyra
kyra8mo ago
Gimme a sec, Youssef
Youssef
YoussefOP8mo ago
well i know, i want to see if there is another way to this with sapphire
UndiedGFX
UndiedGFX8mo ago
good lord i didnt delete that repo
Youssef
YoussefOP8mo ago
Take your time, and thank you so much for helping
UndiedGFX
UndiedGFX8mo ago
the tag response, kyra
kyra
kyra8mo ago
Check this in your bot, @youssef s!ev client.application.commands.cache;
Skyra
Skyra8mo ago
Output: ⏱ 502.26μs
Collection(11) [Map] {
'1205923078627000381' => [ApplicationCommand],
'1205923078627000382' => [ApplicationCommand],
'1226164940306383019' => [ApplicationCommand],
'1226164940306383020' => [ApplicationCommand],
'1226164940306383021' => [ApplicationCommand],
'1226164940306383022' => [ApplicationCommand],
'1226164940306383023' => [ApplicationCommand],
'1226164940847583322' => [ApplicationCommand],
'1226164940847583323' => [ApplicationCommand],
'1226164940847583324' => [ApplicationCommand],
'1226164940847583325' => [ApplicationCommand]
}
Collection(11) [Map] {
'1205923078627000381' => [ApplicationCommand],
'1205923078627000382' => [ApplicationCommand],
'1226164940306383019' => [ApplicationCommand],
'1226164940306383020' => [ApplicationCommand],
'1226164940306383021' => [ApplicationCommand],
'1226164940306383022' => [ApplicationCommand],
'1226164940306383023' => [ApplicationCommand],
'1226164940847583322' => [ApplicationCommand],
'1226164940847583323' => [ApplicationCommand],
'1226164940847583324' => [ApplicationCommand],
'1226164940847583325' => [ApplicationCommand]
}
Youssef
YoussefOP8mo ago
alright give me a seccond
kyra
kyra8mo ago
It should contain all registered commands for the client
UndiedGFX
UndiedGFX8mo ago
i get it nvm
kyra
kyra8mo ago
The reason why this would work, Undied, is because Youssef is registering in the client scope, see ^
UndiedGFX
UndiedGFX8mo ago
i forgot the way djs cache actually worked
Youssef
YoussefOP8mo ago
No description
Youssef
YoussefOP8mo ago
hmm i tried creating a command, restarting the bot , run this it doesn't contain the created command
Youssef
YoussefOP8mo ago
although when i try it after creating the command exacly (so no restart), it has the command
No description
kyra
kyra8mo ago
Does the custom command exist on Discord when you try /asana?
UndiedGFX
UndiedGFX8mo ago
if i remember, the djs cache adds guild commands when someone runs it, i might be totally wrong as well
kyra
kyra8mo ago
Undied, those aren't guild commands.
Youssef
YoussefOP8mo ago
yes when i don't restart, it does exist
UndiedGFX
UndiedGFX8mo ago
the /asana is a guild one kyra
kyra
kyra8mo ago
Not a guild command, see the code ^
UndiedGFX
UndiedGFX8mo ago
, interaction?.guild.id
kyra
kyra8mo ago
Ok, sorry, I stand corrected I could barely see that, the font is too small
UndiedGFX
UndiedGFX8mo ago
kyra can we atleast force djs cache to add something to it?
kyra
kyra8mo ago
Well, for guilds, you'd have to fetch with the guild Considering that information, you'll have to store the IDs in the database 😅
Youssef
YoussefOP8mo ago
kyra, is there way to add the command when i create it to the "collection or the thing" that sapphire use
UndiedGFX
UndiedGFX8mo ago
that is discord.js' cache and i'm afraid the guild commands are added only when someone executes it the same way members are cached
Youssef
YoussefOP8mo ago
and after that, the problem is more saphire side
UndiedGFX
UndiedGFX8mo ago
discord.js side*
Youssef
YoussefOP8mo ago
no? why is it djs side?
UndiedGFX
UndiedGFX8mo ago
sapphire doesnt have this "collection" or cache it is purely djs
Youssef
YoussefOP8mo ago
the command is created correcly, it's when the bot got resttarted
kyra
kyra8mo ago
For fetching guild commands, you need to pass the guild ID to ApplicationCommandManager#fetch
UndiedGFX
UndiedGFX8mo ago
discord,js cache doesnt work the way you think
Favna
Favna8mo ago
the only cache that sapphire has is a list of commands from the commands files and it matches ids from discordjs to them
kyra
kyra8mo ago
Sapphire doesn't know that a command was created under a guild
UndiedGFX
UndiedGFX8mo ago
@youssef if only there was a way you could force the cache
Youssef
YoussefOP8mo ago
What im saying is, the command is created correcly, it's when the bot got restarted and saphire gonna deploy the command it will not find this command
kyra
kyra8mo ago
Youssef, you're not being misunderstood Thing is, this is a Discord limitation, not a Discord.js or a Sapphire one
UndiedGFX
UndiedGFX8mo ago
even if you do it without sapphire and only djs, it will be the same limitation
Youssef
YoussefOP8mo ago
so what should i do exactly?
UndiedGFX
UndiedGFX8mo ago
1) force feed the cache by fetching guild commands on startup
kyra
kyra8mo ago
There's no such endpoint that returns global and ALL guild commands Neither Discord.js nor Sapphire knows which guilds have custom commands
Youssef
YoussefOP8mo ago
if i register the command globally, will it work?
kyra
kyra8mo ago
Yes
UndiedGFX
UndiedGFX8mo ago
yes
kyra
kyra8mo ago
But it'll be available in all guilds, idk if that's desirable for you Question, why do you need that cache populated?
UndiedGFX
UndiedGFX8mo ago
no point but thats what they asked for
kyra
kyra8mo ago
More often than not, bots should not care about whether a command exists in their cache, Discord will send you all the information you need to locate the command
Youssef
YoussefOP8mo ago
hmm, i just want the command to stay in the discord
UndiedGFX
UndiedGFX8mo ago
it does
kyra
kyra8mo ago
Populating that cache will do nothing, that's the thing Sapphire won't delete it, nor will Discord.js
Youssef
YoussefOP8mo ago
it does not when i restart the bot, it get removed
UndiedGFX
UndiedGFX8mo ago
@youssef you have to do this, you are forced to; there is no other way round it doesnt get removed, the cache gets refreshed
Youssef
YoussefOP8mo ago
bro it got deleted when i restarted the bot
kyra
kyra8mo ago
Register the command, restart the bot, restart Discord, tell me if it exists in the UI
UndiedGFX
UndiedGFX8mo ago
from the discord app?
Youssef
YoussefOP8mo ago
alright yes
UndiedGFX
UndiedGFX8mo ago
it shouldnt, right?
Youssef
YoussefOP8mo ago
it got removed after restaring
UndiedGFX
UndiedGFX8mo ago
youssef would you mind if i take a look on the server?
Youssef
YoussefOP8mo ago
wait im gonna share the video
Youssef
YoussefOP8mo ago
No description
Youssef
YoussefOP8mo ago
Video Upload & Annotation - Gemoo
Record you and your screen to clarify your points. Get vidoes organized as mind map, calendar, or any layout. And share it with a link to boost your productivity.
kyra
kyra8mo ago
In that case, @vladdy you know about this better than me (since you wrote the registries), is there any code removing registered application commands on a guild level?
Solution
vladdy
vladdy8mo ago
Only if you use bulk overwrite
vladdy
vladdy8mo ago
Otherwise we do not delete commands, never have, never will
kyra
kyra8mo ago
That's the first thing I said, here ^ So...
vladdy
vladdy8mo ago
Yeah well that's the only place where we actually may delete commands
kyra
kyra8mo ago
Youssef, are you using BulkOverwrite?
Youssef
YoussefOP8mo ago
I don't think so
Youssef
YoussefOP8mo ago
No description
Youssef
YoussefOP8mo ago
that's my client class
kyra
kyra8mo ago
BulkOverwrite isn't written there
vladdy
vladdy8mo ago
Wait what's the issue
Youssef
YoussefOP8mo ago
No description
vladdy
vladdy8mo ago
I'm omw from an exam so bare with stupid questions
kyra
kyra8mo ago
Youssef is registering a guild command manually from a command But after restarting the bot, the guild command gets deleted Code here for the registering, which is inside /tag's chatInputRun method ^
vladdy
vladdy8mo ago
That's... Impossible unless they've set the default behavior to bulk before, then removed it, and tsc didn't update Assuming ts code of course
kyra
kyra8mo ago
It's TS, yes
vladdy
vladdy8mo ago
or they have a listener that deletes commands
Youssef
YoussefOP8mo ago
im checking the files just a sec
Youssef
YoussefOP8mo ago
Actually yes 🥲
No description
Youssef
YoussefOP8mo ago
removing it, should fix the problem i guess. what should behaviour should i put instead?
UndiedGFX
UndiedGFX8mo ago
.Overwrite
kyra
kyra8mo ago
Overwrite is fine, yes
vladdy
vladdy8mo ago
Overwrite or VerboseOverwrite Or none Default is overwrite anyways
Youssef
YoussefOP8mo ago
Alright i will try edit: worked! i can listen to the interactionCreate?, because for the custom command created, i need to reply but it doesnt have file so i'll reply in the code (getting data from the database) @kyra 🩵🩷🤍🩷🩵?
Favna
Favna8mo ago
Yes But uh I think we emit an event when there is no match You should listen to that to ensure that not 2 run side by side That'll get very fucky I can't check rn I'm about to drive But if you check the sapphire code for how we handle interactions (listeners) should be able to find it fairly easily We have our own interaction create
Youssef
YoussefOP8mo ago
alright i'll do that thanks it's UnknownChatInputCommand
UndiedGFX
UndiedGFX8mo ago
dont forget to "mark solved" whatever helped you
Youssef
YoussefOP8mo ago
how
Youssef
YoussefOP8mo ago
@Favna Using this event, log's nothing
No description
Favna
Favna8mo ago
name of the file? and did you rebuild TS code this time?
Youssef
YoussefOP8mo ago
UnknownChatInputCommand yes
Favna
Favna8mo ago
change it to a small letter u at the start or set the event in the constructor and if you do the former remember to nuke dist bet ween rebuilds, tsc wont delete old files
Youssef
YoussefOP8mo ago
That's actually so dumb changing the file name, then running tsc change nothing on the dist
Favna
Favna8mo ago
it's not. The file name has to match the name of the event and the event is camelCased not PascalCased
Youssef
YoussefOP8mo ago
No no, im talking about typescript Thank you so much it worked :) @Favna
Want results from more Discord servers?
Add your server