token is undefined
So, i was just trying to create a bot that can have simple slash commands so i can remind some points that i studied that day and so on. But it gives me the following error when i run node index.js:
The code:
In the .env file, i have the TOKEN copy+paste from the Discord Applications part. I think it may be a simple error but if anyone can help (:
12 Replies
Have you tried logging the process.dotenv to see what it gives you?
actually no, how can i do that? i'm relearning things now from a big break
You should be able to, if
process.dotenv
is undefined try to just log process
. I've never grabbed multiple variables like that admittedly; from what I remember I usually just do something like
Obviously that's going to get annoying if you have multiple variables like you have, but if you can't get it to work it's a way
Ah sorry I didn't read your error message, try just logging process
and see if that's undefined too
Wait, have you tried just process.env
? I don't think process.dotenv
is a thingoh wait, really? i was wondering about using only
process.env
instead of .dotenv
but i was following along with a tutorial that uses .dotenv itself
oh vince, thanks again lol now is workingin the tutorial is like that and it worked
so this made me get a little lost along the way, also is a few months old, so prob is that the issue?
Great 🙂
Here's a bit more of a common approach from the dotenv's npm page (https://www.npmjs.com/package/dotenv):
So you don't need to even set the dotenv variable
Lol that's why I pretty much never follow youtube tutorials unless I'm really going through it 😂
Docs are much more informative and up to date (usually) but if I'm desperate I'll try YT
So i should make my code like:
?
lol is funny how this is working perfect but i got stuck for 20 minutes on that part xD
got it, i'll read more about dotenv in the link you send me 🙋
Lol yea, that should work, you can have multiple variables destructured too so you can do
I get stuck on stupid stuff all the time don't sweat it everyone does lol, not even your fault anyway the tutorial was just old
when following tutorials, i should follow and always read the docs to see if is up to date or only when it gets an error?
It's up to you, if I was doing that I would just go until I get an error. The problem is though sometimes things might still work, but the docs might be more up to date and adopt a newer and better approach if that makes sense
Tutorials are great to follow along to when you get stuck but it might be better for you to try and read the docs first, usually they have examples to get you up and running relatively quickly. Tutorials on youtube can be out of date in months with how fast tech in the web moves
oh got, thanks a lot, vince (: