Mapping command data to an ApplicationCommand

Hi, I'm trying to make a way to recognize if there's an ApplicationCommand that matches (exactly) the data from a SlashCommandBuilder. I checked this https://old.discordjs.dev/#/docs/discord.js/14.14.1/class/ApplicationCommand?scrollTo=equals but it seems to take the entire ApplicationCommand data (like application id), and I couldn't find another related method that works only for the data of the command itself. Ideally I want something built-in inside djs, without needing to code this check myself. Thanks!
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
10 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Amgelo
AmgeloOP9mo ago
I'm trying to make my command registration logic, currently I register commands on start (the easy way, since I know which command is which) but I want to change it so I only register commands I need/changed and unregister the rest
sludge
sludge9mo ago
Well if you use the set method on Client.application.commands it’ll register anything that’s new, update anything that already exists and delete anything that’s no longer needed - all in one go
Amgelo
AmgeloOP9mo ago
well yes, that's what I'm currently using, but the point is that I only want to deploy if needed
sludge
sludge9mo ago
I don’t think you’re going to find a simple way of doing it if you specifically want the code to know when it should and shouldn’t deploy
Amgelo
AmgeloOP9mo ago
well if there's a way to do what I mention (built in djs), it would be fairly simple I didn't see it that way, that's a really good point what would you recommend? I can't really do it like the guide (a deploy script) because I don't have a single source of truth like a commands folder, my commands are registered on the bot dynamically and I don't really want to change that though I think it'd still be better because when re-deploying, the clients' cache are still with the old commands, and users get a client error when trying to use the command for the first time after a bot start (even if the command data didn't change at all) if I deploy only when needed that wouldn't happen currently, commands can be registered before starting the bot but it only saves them internally, after starting it deploys them with #set(); if a command is registered after logging in, it deploys it individually this is a downside though the client's, I'm not sure if cache is the right term but you get a clientside error after using a command that was redeployed something like "non valid application command interaction" I don't recall the exact error after using it for a second time it doesn't happen again, I assume because the client was updated restarting the client fixes it as well
sludge
sludge9mo ago
only time I see that error is if I use an apps command, redeploy and then try to use the command again without changing channel and/or guild to refresh there's nothing you can do on the dev side of things to alter how that works
Amgelo
AmgeloOP9mo ago
the solution would be to not deploy unnecessarily which is what I'm trying to achieve
sludge
sludge9mo ago
even if your app had the maximum number of commands, and you make a change to just one of those 100 commands, you'd still see that error because the client (your app client) will still want/need to refresh the commands available
Amgelo
AmgeloOP9mo ago
are you sure? from my knowledge, that'd happen if I set all the commands, but not if I only set that one command the error would only happen to only that command which is indeed unavoidable but better than all of them what I'm describing happens with a ApplicationCommandManager#set(), which I assume means refreshing all of them without exceptions hence why it'd happen even with commands with no changes does it matter if the data array isn't in the same order? no, all I'm doing is one set call ah nvm, when searching I did have one, must've forgotten it while developing this should be fine then, right? since it wouldn't change anything at all it'd be one unnecessary api call though but still
Want results from more Discord servers?
Add your server