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
UndiedGFX7mo ago
so it don't get removed
it does not get removed
Youssef
YoussefOP7mo ago
it does
kyra
kyra7mo ago
If you're using BulkOverwrite, yes If you use Overwrite or any other strategy, it shouldn't
Youssef
YoussefOP7mo ago
im talking about this command, btw
No description
Youssef
YoussefOP7mo ago
not the command file
UndiedGFX
UndiedGFX7mo ago
you should not create commands like that that is anti-sapphire
Youssef
YoussefOP7mo ago
Im not registering the other commands like this.
kyra
kyra7mo 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
YoussefOP7mo ago
exactly, thanks for understanding
UndiedGFX
UndiedGFX7mo ago
if a command is created in a guild, it shouldnt be removed after logout right?
Youssef
YoussefOP7mo 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
kyra7mo 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
UndiedGFX7mo ago
store in a database
kyra
kyra7mo ago
Why store in a database when Discord gives it to us + we fetch it anyways
kyra
kyra7mo ago
Gimme a sec, Youssef
Youssef
YoussefOP7mo ago
well i know, i want to see if there is another way to this with sapphire
UndiedGFX
UndiedGFX7mo ago
good lord i didnt delete that repo
Youssef
YoussefOP7mo ago
Take your time, and thank you so much for helping
UndiedGFX
UndiedGFX7mo ago
the tag response, kyra
kyra
kyra7mo ago
Check this in your bot, @youssef s!ev client.application.commands.cache;
Skyra
Skyra7mo 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
YoussefOP7mo ago
alright give me a seccond
kyra
kyra7mo ago
It should contain all registered commands for the client
UndiedGFX
UndiedGFX7mo ago
i get it nvm
kyra
kyra7mo ago
The reason why this would work, Undied, is because Youssef is registering in the client scope, see ^
UndiedGFX
UndiedGFX7mo ago
i forgot the way djs cache actually worked
Youssef
YoussefOP7mo ago
No description
Youssef
YoussefOP7mo ago
hmm i tried creating a command, restarting the bot , run this it doesn't contain the created command
Youssef
YoussefOP7mo ago
although when i try it after creating the command exacly (so no restart), it has the command
No description
kyra
kyra7mo ago
Does the custom command exist on Discord when you try /asana?
UndiedGFX
UndiedGFX7mo ago
if i remember, the djs cache adds guild commands when someone runs it, i might be totally wrong as well
kyra
kyra7mo ago
Undied, those aren't guild commands.
Youssef
YoussefOP7mo ago
yes when i don't restart, it does exist
UndiedGFX
UndiedGFX7mo ago
the /asana is a guild one kyra
kyra
kyra7mo ago
Not a guild command, see the code ^
UndiedGFX
UndiedGFX7mo ago
, interaction?.guild.id
kyra
kyra7mo ago
Ok, sorry, I stand corrected I could barely see that, the font is too small
UndiedGFX
UndiedGFX7mo ago
kyra can we atleast force djs cache to add something to it?
kyra
kyra7mo 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
YoussefOP7mo ago
kyra, is there way to add the command when i create it to the "collection or the thing" that sapphire use
UndiedGFX
UndiedGFX7mo 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
YoussefOP7mo ago
and after that, the problem is more saphire side
UndiedGFX
UndiedGFX7mo ago
discord.js side*
Youssef
YoussefOP7mo ago
no? why is it djs side?
UndiedGFX
UndiedGFX7mo ago
sapphire doesnt have this "collection" or cache it is purely djs
Youssef
YoussefOP7mo ago
the command is created correcly, it's when the bot got resttarted
kyra
kyra7mo ago
For fetching guild commands, you need to pass the guild ID to ApplicationCommandManager#fetch
UndiedGFX
UndiedGFX7mo ago
discord,js cache doesnt work the way you think
Favna
Favna7mo 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
kyra7mo ago
Sapphire doesn't know that a command was created under a guild
UndiedGFX
UndiedGFX7mo ago
@youssef if only there was a way you could force the cache
Youssef
YoussefOP7mo 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
kyra7mo ago
Youssef, you're not being misunderstood Thing is, this is a Discord limitation, not a Discord.js or a Sapphire one
UndiedGFX
UndiedGFX7mo ago
even if you do it without sapphire and only djs, it will be the same limitation
Youssef
YoussefOP7mo ago
so what should i do exactly?
UndiedGFX
UndiedGFX7mo ago
1) force feed the cache by fetching guild commands on startup
kyra
kyra7mo 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
YoussefOP7mo ago
if i register the command globally, will it work?
kyra
kyra7mo ago
Yes
UndiedGFX
UndiedGFX7mo ago
yes
kyra
kyra7mo 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
UndiedGFX7mo ago
no point but thats what they asked for
kyra
kyra7mo 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
YoussefOP7mo ago
hmm, i just want the command to stay in the discord
UndiedGFX
UndiedGFX7mo ago
it does
kyra
kyra7mo ago
Populating that cache will do nothing, that's the thing Sapphire won't delete it, nor will Discord.js
Youssef
YoussefOP7mo ago
it does not when i restart the bot, it get removed
UndiedGFX
UndiedGFX7mo 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
YoussefOP7mo ago
bro it got deleted when i restarted the bot
kyra
kyra7mo ago
Register the command, restart the bot, restart Discord, tell me if it exists in the UI
UndiedGFX
UndiedGFX7mo ago
from the discord app?
Youssef
YoussefOP7mo ago
alright yes
UndiedGFX
UndiedGFX7mo ago
it shouldnt, right?
Youssef
YoussefOP7mo ago
it got removed after restaring
UndiedGFX
UndiedGFX7mo ago
youssef would you mind if i take a look on the server?
Youssef
YoussefOP7mo ago
wait im gonna share the video
Youssef
YoussefOP7mo ago
No description
Youssef
YoussefOP7mo 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
kyra7mo 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
vladdy7mo ago
Only if you use bulk overwrite
vladdy
vladdy7mo ago
Otherwise we do not delete commands, never have, never will
kyra
kyra7mo ago
That's the first thing I said, here ^ So...
vladdy
vladdy7mo ago
Yeah well that's the only place where we actually may delete commands
kyra
kyra7mo ago
Youssef, are you using BulkOverwrite?
Youssef
YoussefOP7mo ago
I don't think so
Youssef
YoussefOP7mo ago
No description
Youssef
YoussefOP7mo ago
that's my client class
kyra
kyra7mo ago
BulkOverwrite isn't written there
vladdy
vladdy7mo ago
Wait what's the issue
Youssef
YoussefOP7mo ago
No description
vladdy
vladdy7mo ago
I'm omw from an exam so bare with stupid questions
kyra
kyra7mo 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
vladdy7mo 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
kyra7mo ago
It's TS, yes
vladdy
vladdy7mo ago
or they have a listener that deletes commands
Youssef
YoussefOP7mo ago
im checking the files just a sec
Youssef
YoussefOP7mo ago
Actually yes 🥲
No description
Youssef
YoussefOP7mo ago
removing it, should fix the problem i guess. what should behaviour should i put instead?
UndiedGFX
UndiedGFX7mo ago
.Overwrite
kyra
kyra7mo ago
Overwrite is fine, yes
vladdy
vladdy7mo ago
Overwrite or VerboseOverwrite Or none Default is overwrite anyways
Youssef
YoussefOP7mo 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
Favna7mo 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
YoussefOP7mo ago
alright i'll do that thanks it's UnknownChatInputCommand
UndiedGFX
UndiedGFX7mo ago
dont forget to "mark solved" whatever helped you
Youssef
YoussefOP7mo ago
how
Youssef
YoussefOP7mo ago
@Favna Using this event, log's nothing
No description
Favna
Favna7mo ago
name of the file? and did you rebuild TS code this time?
Youssef
YoussefOP7mo ago
UnknownChatInputCommand yes
Favna
Favna7mo 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
YoussefOP7mo ago
That's actually so dumb changing the file name, then running tsc change nothing on the dist
Favna
Favna7mo ago
it's not. The file name has to match the name of the event and the event is camelCased not PascalCased
Youssef
YoussefOP7mo ago
No no, im talking about typescript Thank you so much it worked :) @Favna
Want results from more Discord servers?
Add your server