Node.js bot start issues.
When I try running my node index1.js (yes there is a 1), I just get a reply with big green letters saying “MODULE_NOT_FOUND”.
195 Replies
If the module isn't found then you install that module
Would suggest to read djs guide to get a working bot up
Also, please send the contents of index1.js so we can give more descriptive help
I think I might know how to fix
Ok nevermind my fix didn’t fix it
Yes give me one second please.
@Lioness100
And what was the full error you received?
All of it please
And two general things:
- You don't need to do
client.on('messageCreate', ...)
for every command. That can get very bad for performance. Instead just put it all in one:
- Second, if you're using a prefix of /
, why don't you just use slash commands?What about slash commands?
Chances are you're using an absolute path instead of a relative one to execute the files. So instead of "index1.js in this folder", the system is understanding "index.js in the base file of the computer (or your user)"
So please show what command you used
to start the bot
node index1.js
You're in the wrong folder in the terminal, then
What is the path to the folder where index1.js is?
For example, C:\Users\kodel\code\something\other\index1.js?
Discord
Slash Commands FAQ
Slash Commands are here! No more guessing how commands work or trying to figure out which ID goes where. Slash Commands are here to make your life a whole lot easier.
WHAT ARE SLASH COMMANDS?
Slash...
I am very new to coding so I just made it as basic as possible and if I ask wym that is why
You can see them if you type in
/
right now in chatGive me like 2 minutes I need to go back to my laptop I am on mobile right now so I will look when I can in a few minutes
That's fine, but I strongly strongly recommend you go by the discord.js guide: https://discordjs.guide/
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
That will help you with the bot, the file system, figuring out slash commands, and further
its
c:\users\kodel\index1.js
Run
ls
in the terminal and screenshot the response
@Lioness100 ^^
don't tag her with all reply please. She will reply at her ease. You're not having package.json and other things
sorry 🤷♂️
So just follow the guide step by step and you will be fine
I did
I doubt
I simply cannot get it to start
are you using vsc?
yes
It would be a good idea to create a new folder for the bot to keep everything organized
As Priyam mentioned, it doesn't look like you have a package.json, lock file, or node_modules
I have a package.json
ls
displays every file/subfolder in a folder, and the package.json
isn't shown. Is it in a different folder?its in the same folder as index1.js
I put it all in 1 folder
Run
cat package.json
and screenshot the response pleasepackage1.json
is different from package.json
. The naming is required to be exactyes I know
my file is package1.json
not package.json
I'm saying that to run node, the file has to be called
package.json
how do I change it
I can't right click on the file in vsc
Please screenshot the file structure on vsc
this stuff
You are fast in sending 😛
Ok, so it doesn't look like the files are in
C:\Users\kodel
as you said, but instead some folder in AppData
So:
- you have to be in the same folder in the terminal as those files to run the bot
- package1.json and package-lock1.json cannot have the "1" to be recognized by node
- .env1.txt won't be recognized by dotenv, you have to call it .env
I took my best guess with what file because I am totally new to coding and I didn't understand half of what you said
From the name in the package1.json, I'm guessing you followed a guide on youtube or copied code from github?
yes
I'd recommend using the official guide, the one I linked above
how do I change the names of the files though?
right click them
that is the right click box 🤷♂️
But honestly I'd recommend just copying the contents of index1.js and start over using the official guide, because you're in a bit of a disorganization right now
Don't click it on the top, click it on the side where you screenshotted
not here
here
I clicked on one of the files (on the side)
I have to go I'll be back later
It might be a permission issue if vscode doesn't have permission to delete files
Idk how you have everything set up, I'd generally recommend official guides over others, because they're much more reputable, and it's easier for people to help you if they know that you're setup is reliable
didn't read everything but I guess you did something wrong in line 2
that's not wrong actually, dotenv/config is a valid entrypoint
I use it my bot too, I forget what version it was introduced in but it's relatively recent
It's just a shortcut if you have no parameters to add in to the config call, which also means it's usable in the start command (
node -r dotenv/config index.js
)Nevermind lol, it's been a thing since 2015
idk why I thought it was recent
lol
whaaa why is that inside AppData that happens for untrusted folders
That makes sense if it's in AppData
Maybe also why PowerShell wouldn't cat it? But idk PowerShell or if OP was in the right directory anyways
So @Shxdow ツ, when you get back, move the folder with these files out of appdata
Ok
Thank you so much Lioness I figured it out because of you!
But I still can't run it because apparently Discord.js isn't installed on Node.js
?
Run
npm i
and try again. If that doesn't work, please show your files again like thiswant me to show you the error message I get when I run that?
Yes
I think it's because of the restricted permission on a base user folder. You'll have to put those 4 files in a new folder
Like, C:\Users\kodel\discord-bot\
ok
so I made the folder
C:\Users\kodel\shxdow-bot
. Just move all of the files there? and what command to run, node shxdow-bot
?Move all the files there, then run
cd shxdow-bot
, which will move which folder you're in from the terminal, then run npm i
, and then run node index.js
ok thanks
I really appreciate your help so here is the bio of my bot (I will remove if you want).
Samuel is my friend who fixed all of my original errors and then referred me to a few servers to get the other problems (which you fixed)
Damn it when did my tag change
That's bad news I have #4566 everywhere for instructions on how to reach out to me
haha lol
Thanks haha though
erm
Could you run
ls
?I have worked on this bot for 8+ hours now 😭 💀
Just out of curiosity, run
npm i discord.js
holy shit it is doing a lot of stuff 💀
done
I ran node index.js and here is what it replied with
did you make
index.js
a folder and put index.js
insideyes 💀
Whatever lol, just run
npm i dotenv
and it will work
As long as the .env file is in there somewhere tooIt is
and I did that and then
node index.js
and it replied with thisfixed that error
Did you add more to your code since this?
one line
but I removed it
and now I get this
That means that your .env in fact is not "in there" :))
i'll show you lol
this is my index.js file
or folder rather
What's in the .env
TOKEN=(bot token)
Oh
It's cuz you did process.env1
That's not a thing, it's process.env
oh fuck me
What's your thing with ones
its a long story
lol I forgot I reset the bot token as well hahahahaha
lemme fix that and it should hopefully work
Out of curiosity, are you doing this just to make a bot, or do you want to learn to code too?
both 😄
we have a problem
when I reset the token it just says the same token as before
In that case, I'd recommend you:
- start following official guides over YouTube videos
- stop copying code if you don't know how it works
- learn to Google your errors before asking someone else for help
I want to make a bot first, then I will actually learn to code 😅
thank you
.
Like, you reset the token on the discord portal, and when you copy the new one, it's the same?
yes
Then just use that one
but it says invalid token when I paste it in VSC
and run node
index.js
Idk how to help you, I guess just make sure you're actually resetting it and you're actually copying the new one
erm question
That's what I did too, but it will very much be easier if you put some effort into understanding the programming language and library
Before you make a Discord Bot, you should have a good understanding of JavaScript. This means you should have a basic understanding of the following topics:
- Read and understand docs
- Debug code
- Syntax
- NodeJS module system
If you aren't sure that your understanding of JavaScript is truly good enough to make a bot, you should really try to continue learning first. Here are good resources to learn both Javascript and NodeJS:
Codecademy: https://www.codecademy.com/learn/javascript
Udemy: https://www.udemy.com/javascript-essentials/
Eloquent JavaScript, free book: http://eloquentjavascript.net/
You-Dont-Know-JS: https://github.com/getify/You-Dont-Know-JS
JavaScript Garden: https://bonsaiden.github.io/JavaScript-Garden/
JavaScript reference/docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
Nodeschool: https://nodeschool.io/
Pluralsight: https://www.codeschool.com/courses/real-time-web-with-node-js
Before you ask a question, you should ask these yourself:
1) Is this question related to JavaScript, or the library I am using? - If it is the library you are using, go to the proper server. You would get better answers there.
2) Have I tried to google and / or check StackOverflow? - Double check that you can't find anywhere that can lead you to a solution online.
3) Have I tried to look on MDN or the library documentation? - You should always check documentations to make sure you aren't missing how any details.
4) Does my question make enough sense so that people can understand it, and do they understand what I am trying to accomplish? - If no, revise your question. Give as much detail as possible. Include any error or code output that can help us help you.
5) Am I aware of what I am doing, and not just mindlessly copy and pasting? - If you are just copy and pasting code from a guide, you are not going to be able to solve anything. Make sure you understand the code you are writing.
Sorry that's a huge block of text
But good info
if I were to create a new bot with a different token and put that as the token will that be a different bot (meaning if the token is glitched I can just create the same bot with a valid token will it do anything with the code)
Yes
But I really doubt the token is "glitched"
I will try it 😭
Maybe send a screen recording of this happening to you?
with the token there? 💀 not a chance
You can reset it after lol
Anyways, whatever works
I keeo getting this message -_-
oh hold up
that doesn't mean the token is invalid, that means you're not inputting the token correctly
I'll show you exactly what I am doing (with a totally fake token)
TOKEN=M7innsyI8bsg
Please send your index.js code again
bro what the heck is that
no hate 💀
client.on("ready", async () => {} ,client.login (process.env.TOKEN))what were hoping to achieve with this? take me through your train of thought no hate
the first line you have there was suggested by a person in another server...
the second line is to run the env file
OK, well fix it by replace both of those lines with just
client.login (process.env.TOKEN))
with the space?
the first line you have there was suggested by a person in another server...And send me a screenshot of that lol space doesn't matter, idk why it's there in the first place
lol
but whatever you think looks the best
I left the server
I swear I am not lying
I swear ong bro
I'm just wondering if you royally misunderstood or the person has no idea what they're talking about
they put it in `` and told me to copy and paste
5) Am I aware of what I am doing, and not just mindlessly copy and pasting? - If you are just copy and pasting code from a guide, you are not going to be able to solve anything. Make sure you understand the code you are writing.hint: this is why
lol
I get the same message
I copied what you put and then fixed the errors it told me to fix
Send me your code again
can I friend request you? you literally are such a relief
Sure
ty
can you screenshot the error again? Just so I can make sure it's exactly the same
I am having trouble lining it up to perfectly fit so here it is in text
Above
client.login(process.env.TOKEN)
, create a new line and write console.log(process.env.TOKEN)
, currently, the error is saying that either process.env.TOKEN
is undefined or isn't a string, so just log it to console to see exactly what it is💀
I might have a fix hold up
nvrm
I figured if I added
var
in front it might work but noIf you want a quick and dirty fix, just replace process.env.TOKEN with your actual token, skip the step of using a .env file, and just don't share the code
🎉
I wasn't going to either way hahahaha
put ' or no?
yes
'token'
all strings need to have quotes around them
inside ()
lol
I wasn't joking lol
that is why it wasn't working before
I didn't have '' around the token after TOKEN:
I had
TOKEN=ndhua7**&^jy
ah
it should be
TOKEN:'jshyujsgjh'
yes?the quotes don't apply for .env
oh
lol
Also it's a "=", not ":"
typo mb
I had = in the env
oh fuck me
when I replace the process.env.TOKEN and put '0te81u7hj' this is the message I get when I run
node index.js
help meh Lioness 😭
easy fix
?
go to discord developer portal, bot tab, scroll down and make sure message content is checked
🤭
I LOVE YOU
follow me on github
I don't have a github acc 🤣
you'll never make it as a developer without a github account one and then follow me
ok
erm
question
how do I add a custom status?
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
ty ❤️
you should put that code in the ready event
what is the ready event?
💀
(because you can only set the status after the bot finished logging in)
just read
read the guide
from the beginning
please
this is your ready event
By "put code in there", I mean:
ok
so the code to add the custom status is 'this code is in here'?
no
that's a console.log function, which logs strings or objects or things to the terminal
right
so put my whole code in the console? 💀
no, that was just an example line of code
lol
I can't type in the terminal now @Lioness100
sorry for ping -_-
that's because the bot process is running
how do I stop it?
you can either press Ctrl+C, which will stop the bot so you can use the terminal for other things
or create a new terminal, which you can do with the plus button or with Ctrl+Shift+`
ty
Thank you so very much Lioness!
yay I had another pre-coded bot awhile back and now I got dev badge from it
it was literally "paste your token here and get a free bot"
boom
(not this bot an old one)