#Node.js bot start issues.
1 messages · Page 1 of 1 (latest)
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
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:
client.on('messageCreate', async (message) => {
if (message.content === '/hello') {
return message.reply('Hello!')
}
if (message.content === '/goodnight') {
return message.reply('Goodnight! Sleep tight! Do not let Shxdow bite!')
}
if (message.content === '*ping') {
return message.reply('Pong!')
}
if (message.content === '!dev') {
return message.reply('The developer of this bot is Shxdowツ#3697')
}
if (message.content === '/invite') {
return message.reply('https://discord.com/api/oauth2/authorize?client_id=1061187877431689298&permissions=8&scope=bot%20applications.commands')
}
if (message.content === '/commands') {
return message.reply('/hello, /goodnight, *ping, !dev, /invite')
}
})
- Second, if you're using a prefix of
/, why don't you just use 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
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 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...
You can see them if you type in / right now in chat
That's fine, but I strongly strongly recommend you go by the discord.js guide: https://discordjs.guide/
That will help you with the bot, the file system, figuring out slash commands, and further
Run ls in the terminal and screenshot the response
don't tag her with all reply please. She will reply at her ease. You're not having package.json and other things
So just follow the guide step by step and you will be fine
I doubt
are you using vsc?
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
ls displays every file/subfolder in a folder, and the package.json isn't shown. Is it in a different folder?
Run cat package.json and screenshot the response please
package1.json is different from package.json. The naming is required to be exact
I'm saying that to run node, the file has to be called package.json
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
From the name in the package1.json, I'm guessing you followed a guide on youtube or copied code from github?
I'd recommend using the official guide, the one I linked above
right click them
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
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
- require('dotenv/config');
- require('dotenv').config();
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)

iirc 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 @spark drift, when you get back, move the folder with these files out of appdata
Run npm i and try again. If that doesn't work, please show your files again like this
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\
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
Damn it when did my tag change
That's bad news I have #4566 everywhere for instructions on how to reach out to me
Thanks haha though
Could you run ls?
Just out of curiosity, run npm i discord.js
did you make index.js a folder and put index.js inside
Whatever lol, just run npm i dotenv and it will work
As long as the .env file is in there somewhere too
Did you add more to your code since this?
That means that your .env in fact is not "in there" :))
What's in the .env
Oh
It's cuz you did process.env1
That's not a thing, it's process.env
What's your thing with ones 
Out of curiosity, are you doing this just to make a bot, or do you want to learn to code too?
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
Like, you reset the token on the discord portal, and when you copy the new one, it's the same?
Then just use that one
Idk how to help you, I guess just make sure you're actually resetting it and you're actually copying the new one
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
Yes
But I really doubt the token is "glitched"
Maybe send a screen recording of this happening to you?
You can reset it after lol
Anyways, whatever works
oh hold up
that doesn't mean the token is invalid, that means you're not inputting the token correctly
Please send your index.js code again
bro what the heck is that
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 
OK, well fix it by replace both of those lines with just
client.login (process.env.TOKEN))
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
but whatever you think looks the best
I'm just wondering if you royally misunderstood or the person has no idea what they're talking about 
- 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
Send me your code again
Sure
can you screenshot the error again? Just so I can make sure it's exactly the same
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
If 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
yes
all strings need to have quotes around them
I wasn't joking lol
ah
the quotes don't apply for .env
Also it's a "=", not ":"
easy fix
go to discord developer portal, bot tab, scroll down and make sure message content is checked
follow me on github 
you'll never make it as a developer without a github account 
make one and then follow me 
you should put that code in 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
client.on('ready', async () => {
console.log('The bot is ready')
})
this is your ready event
By "put code in there", I mean:
client.on('ready', async () => {
console.log('this code is in here')
console.log('The bot is ready')
})
no
that's a console.log function, which logs strings or objects or things to the terminal
no, that was just an example line of code
client.on('ready', async () => {
client.user.setStatusOrWhaterveraefhdn()
console.log('The bot is ready')
})
that's because the bot process is running
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+`
