Unable to see (/) commands
I'm trying to follow the guide on the part of creating slash commands, and this is my
main.js file, and my bot is up and running correctly, but the slash command won't show up.59 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!
- ✅ Marked as resolved by staffthis is my
index.js file
this is my ping.js fileThe slash commands arent showing up via discord?
yeah
Bot is running properly though, no errors
Can you show me your
deploy-commands.js file?I haven't gotten to that step yet, I'm following the guide- oh am i supposed to finish that step first-
oh i see
lol sorry, i figured out
Alr good, make sure after, to run node
deploy-commands.jsthat way your commands get registered with dsicord API.oh okay
Thank you
mhm
When running
node deploy-commands.js, i see the "Started refreshing 2 application (/) commands." message, but then I receive an error stating:
Expected token to be set for this request, but none was present
I have my token requiring .env..
This is my deploy-commands.js filehuh?
so instead of
?
You can't import environment variables from "dotenv" instead, you can import them from
process.env which is the global command to access the loaded environment variablesor just
process.env.token
(after running .config())Wait so what part of the code do I replace that with
your require
this ?
change it to the first line here
and instead of
.setToken(token), .setToken(process.env.token)so just add the
.config()No. You can't import environment variables from dotenv. It doesn't work that way
Copy this exactly. Delete what you have
wait wait
^^ packages are (generally) static code, they don't read and automatically export variables based on files (eg based on your .env content)
Do I do anything with this line?
yes, we're both telling you that line is entirely wrong
Do I just COMPLETELY replace it with
That line is not allowed code. { token } doesn't exist for "dotenv"
yes
how about my clientId and guildId?
^^
This
Just add more to the {}
ive done that
then it should work
so my new code would be
no, you didn't remove the line
eh?
ah, you did but changed the require to process.env
well that's a mix of my and Samtino's approach
wait
I'm not really sure if Samtino's works, since process.env is an object
sorry
but if it works then that code should work
even though it's a mix

try removing const { clientId, guildId } = require(process.env); then
and instead access your client and guild ids through the process.env object
like in your setToken
What do you mean?
which part?
Oh cuz I'm dumb. I shouldn't have put require in it. Just
= process.envwdym by accessing client and guild ids through process.env
is that not what i did-
oh
so like this

no, you were requiring which imports a module/library
as if process.env was a library
Alr now it works
in reality it's an object that contains your env variables, after you run the dotenv .config()
Aight thank you
it works
either destructuring (what you showed in the last image) or dot notation (process.env.<name>) works for accessing a value in an object
ah okay
Destructuring is nice if you need multiple variables in the same file. But dot notation doesn't require any imports in any subfiles
Both are correct, and have benefits and downsides for each
Working now?
Yeah
alr
usually when this happens to me is just because my discord client is using the cached commands from my bot (before registering them), so the fix is simply restarting it (ctrl + R)