Handling commands with promises
Hi! So I have been working on this problem for a bit now. I've slowly solved most of the issues I've run into, but this one has me stumped. I know how to handle promises normally, but I cant seem to be able to make it work when loading commands.
Here is a little explanation of the command im making. Basically, In my server we have a command to create characters. That command seems to be working find, but then I made a command that retrieves that character info. In order to avoid having any spelling issues or dealing with case insensitivity What I did was loaded all of the characters in the db using prismaORM and mapped the names so they can be passed into the setChoices method in the EmbedBuilder class. However because this requires async/await it isn't quite working right. Below is my code and a screenshot of the error I'm getting. Thank you in advance for the help on this!
There actually isnt an error, but my condition in index.js is saying "Command with name [] not found. Even though the deploy-commands.js is loading 4 commands (and thats all i have so far.)
62 Replies
- 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!seems like your command isnt being pushed into client.commands then
you'll have to log to see what is being pushed
doesnt seem to be the case, its pushing exactly what Im expecting it to
if it was this wouldnt be your issue
this is part of the log before the commands are deployed
its in there which is why im confused
deploying your commands =/= populating your client.commands
client.commands doesnt exist. its a custom property
which you have to populate with your commands
they are not automatically added
also why are you setting the avatar every time your bot logs in
is that ai code
ah i see
and some of it, not all. I do see that the name of the command when its loading client.commands.set is undefined
index.js specifically is directly from the docs
except the setAvatar. I did add that myself. I didn't know client.once is called every time. Thats on me, ive only been looking into the docs a couple days
good catch on the avatar. I must have put that there yesterday when I got a little frustrated. Moved that right below where client was declared instead
.once is called only the first time the event is called, and in the case of ClientReady it's only called once so it doesn't matter much
I think what he meant is that you don't need to set your avatar on every login, you should only need to do it once via the portal
unless the logo changes for some reason
understood. Not sure why the other person said client.commands doesnt exist
this is directly from the docs
im saying it doesnt exist by default
you create it
and thus you are responsible to populate it
its not bound to the commands you deploy
its in the index.js. Im not sure what you mean
it doesn't exist as in, it's not something managed by djs
it's a property you create as the user
your issue is with you populating your client.commands
you could perfectly name it "incendiumsCommands" for instance and it'd work just the same
which you seem to be confusing with deploying
your command might be deployed
but its not in your client.commands
gotcha so it would be in a configuration file probably right?
okay so heres one small isue with this line of thinking
its right here
my other commands work
then you have to debug and figure out why that command isnt being set into client.commands
helpful...
debugging is core js
I dont mean to be rude, but I have been debugging. If I hadnt been trying for a while now I wouldnt have posted it in here
then log to see what you are setting into client.commands
log the files you are loading
It is undefined when loading into client.commands. i could use some help with where to go from there
log the files you are requiring
and see if your file is in it
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
pretty sure the error should be caused by the method returning a promise, which isn't the data it expects
every async method returns a promise, that's how they work
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
their cursed ai handler accounts for that.
oh wait yeah, should've looked at the handler first
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
indeed
using autocomplete would be much easier imo
you should follow the guide gwapes linked
and use this to register
So the main issue im noticing which is why I it here is that the command being loaded is a promise. That is what is stopping the command from being properly loaded. I had figured that part out. I was wondering if anyone here knew of a good way to handle that situation
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
the client export was a previous issue i hadnt removed, my bad
by not having promises. There is no reason to have a promise in your data
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
slash commands only have to deployed once
there is when you are loading from a database. Prisma takes a moment to load all the data i need.
if you have dynamic choices, use autocomplete
Then you use autocomplete
using autocomplete would also allow you to change your available options in runtime
ill look into that! Sorry I was jumping back and forth
Thought choices was the only option for a choosable string option
do mind the limit is 25 options, so youll have to slice your autocomplete options
well autocomplete works more as a suggestion thing
you should still validate if what the user submitted is valid input
so it would be able to pick from my list of characters from the database? This feels like it might lead to the same issue
no
autocomplete is at runtime
deploying is separate and only once
its a separate script
at least, meant to be
autocomplete makes you receive an interaction when the user types in the option, and you can respond to the interaction which will set what options are shown to the user
further details are in the guide
I'd suggest using some kind of cache though given interactions expire after 3 seconds, and you can't defer autocompletes
Hmmm I dont think this will accomplish what im going for. Well, thank you all for your help. I'll keep looking then. I feel like I'm very close to getting this to work, just need to find a way to resolve the promise before trying to add the command.
remove the promise
remove the options
autocomplete handles that
no need for a db call when deploying
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
with your current method you'd have to redeploy every time your options change
the only thing you need is a
.setAutocomplete(true)
on your option
and then handle that interaction and respond with your choicesAh I see, that gives me a little more insight on the proces then. It preloads data and doesnt get updated as I update the database.....dang it. Welp, it was worth a try> i will look into the autocomplete approach. Thanks yall!
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View