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
Photon
Photon2y ago
If the module isn't found then you install that module Would suggest to read djs guide to get a working bot up
Lioness100
Lioness1002y ago
Also, please send the contents of index1.js so we can give more descriptive help
Shxdow ツ
Shxdow ツ2y ago
I think I might know how to fix Ok nevermind my fix didn’t fix it Yes give me one second please.
const { Client, GatewayIntentBits } = require('discord.js')
require('dotenv/config')

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})

client.on('ready', async () => {
console.log('The bot is ready')
})

client.on('messageCreate', async (message) => {
if (message.content === '/hello') {
message.reply('Hello!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/goodnight') {
message.reply('Goodnight! Sleep tight! Do not let Shxdow bite!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '*ping') {
message.reply('Pong!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '!dev') {
message.reply('The developer of this bot is Shxdowツ#3697')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/invite') {
message.reply('https://discord.com/api/oauth2/authorize?client_id=1061187877431689298&permissions=8&scope=bot%20applications.commands')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/commands') {
message.reply('/hello, /goodnight, *ping, !dev, /invite')
}
})
client.login(process.env1.TOKEN)
const { Client, GatewayIntentBits } = require('discord.js')
require('dotenv/config')

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})

client.on('ready', async () => {
console.log('The bot is ready')
})

client.on('messageCreate', async (message) => {
if (message.content === '/hello') {
message.reply('Hello!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/goodnight') {
message.reply('Goodnight! Sleep tight! Do not let Shxdow bite!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '*ping') {
message.reply('Pong!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '!dev') {
message.reply('The developer of this bot is Shxdowツ#3697')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/invite') {
message.reply('https://discord.com/api/oauth2/authorize?client_id=1061187877431689298&permissions=8&scope=bot%20applications.commands')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/commands') {
message.reply('/hello, /goodnight, *ping, !dev, /invite')
}
})
client.login(process.env1.TOKEN)
@Lioness100
Lioness100
Lioness1002y ago
And what was the full error you received? All of it please
Shxdow ツ
Shxdow ツ2y ago
Lioness100
Lioness1002y ago
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')
}
})
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?
Shxdow ツ
Shxdow ツ2y ago
What about slash commands?
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
node index1.js
Lioness100
Lioness1002y ago
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?
Lioness100
Lioness1002y ago
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...
Shxdow ツ
Shxdow ツ2y ago
I am very new to coding so I just made it as basic as possible and if I ask wym that is why
Lioness100
Lioness1002y ago
You can see them if you type in / right now in chat
Shxdow ツ
Shxdow ツ2y ago
Give 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
Lioness100
Lioness1002y ago
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.
Lioness100
Lioness1002y ago
That will help you with the bot, the file system, figuring out slash commands, and further
Shxdow ツ
Shxdow ツ2y ago
its c:\users\kodel\index1.js
Lioness100
Lioness1002y ago
Run ls in the terminal and screenshot the response
Shxdow ツ
Shxdow ツ2y ago
Directory: C:\Users\kodel


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 12/11/2022 9:48 PM .thumbnails
d----- 1/7/2023 2:51 AM .vscode
d-r--- 11/7/2022 4:28 AM Contacts
d----- 8/29/2022 7:20 AM curseforge
d-r--- 1/7/2023 2:52 AM Desktop
d-r--- 1/7/2023 3:33 AM Documents
d-r--- 1/7/2023 10:49 AM Downloads
d-r--- 11/7/2022 4:28 AM Favorites
d----- 1/7/2023 10:17 AM index1.js
d-r--- 11/7/2022 4:28 AM Links
d----- 10/22/2022 10:45 PM Movies
d-r--- 11/7/2022 4:28 AM Music
dar--l 1/4/2023 11:08 PM OneDrive
d-r--- 11/29/2022 5:16 PM Pictures
d-r--- 11/7/2022 4:28 AM Saved Games
d-r--- 11/7/2022 4:28 AM Searches
d-r--- 11/7/2022 4:28 AM Videos
-a---- 1/7/2023 2:56 AM 17 .node_repl_his
tory
-a---- 10/22/2022 11:15 PM 807403448 10-22-22 Leon
-Edited-.mov
-a---- 10/29/2022 10:45 AM 7727075 Timeline 1.mov
-a---- 10/29/2022 10:32 AM 30478 Wesson
(Fortnite
Montage).drp
Directory: C:\Users\kodel


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 12/11/2022 9:48 PM .thumbnails
d----- 1/7/2023 2:51 AM .vscode
d-r--- 11/7/2022 4:28 AM Contacts
d----- 8/29/2022 7:20 AM curseforge
d-r--- 1/7/2023 2:52 AM Desktop
d-r--- 1/7/2023 3:33 AM Documents
d-r--- 1/7/2023 10:49 AM Downloads
d-r--- 11/7/2022 4:28 AM Favorites
d----- 1/7/2023 10:17 AM index1.js
d-r--- 11/7/2022 4:28 AM Links
d----- 10/22/2022 10:45 PM Movies
d-r--- 11/7/2022 4:28 AM Music
dar--l 1/4/2023 11:08 PM OneDrive
d-r--- 11/29/2022 5:16 PM Pictures
d-r--- 11/7/2022 4:28 AM Saved Games
d-r--- 11/7/2022 4:28 AM Searches
d-r--- 11/7/2022 4:28 AM Videos
-a---- 1/7/2023 2:56 AM 17 .node_repl_his
tory
-a---- 10/22/2022 11:15 PM 807403448 10-22-22 Leon
-Edited-.mov
-a---- 10/29/2022 10:45 AM 7727075 Timeline 1.mov
-a---- 10/29/2022 10:32 AM 30478 Wesson
(Fortnite
Montage).drp
@Lioness100 ^^
Photon
Photon2y ago
don't tag her with all reply please. She will reply at her ease. You're not having package.json and other things
Shxdow ツ
Shxdow ツ2y ago
sorry 🤷‍♂️
Photon
Photon2y ago
So just follow the guide step by step and you will be fine
Shxdow ツ
Shxdow ツ2y ago
I did
Photon
Photon2y ago
I doubt
Shxdow ツ
Shxdow ツ2y ago
I simply cannot get it to start
Photon
Photon2y ago
are you using vsc?
Shxdow ツ
Shxdow ツ2y ago
yes
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
I have a package.json
{
"name": "1---how-to-make-a-discord-bot-for-beginners",
"version": "1.0.0",
"description": "",
"main": "index1.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^14.3.0",
"dotenv": "^16.0.1"
}
}
{
"name": "1---how-to-make-a-discord-bot-for-beginners",
"version": "1.0.0",
"description": "",
"main": "index1.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^14.3.0",
"dotenv": "^16.0.1"
}
}
Lioness100
Lioness1002y ago
ls displays every file/subfolder in a folder, and the package.json isn't shown. Is it in a different folder?
Shxdow ツ
Shxdow ツ2y ago
its in the same folder as index1.js I put it all in 1 folder
Lioness100
Lioness1002y ago
Run cat package.json and screenshot the response please
Shxdow ツ
Shxdow ツ2y ago
Lioness100
Lioness1002y ago
package1.json is different from package.json. The naming is required to be exact
Shxdow ツ
Shxdow ツ2y ago
yes I know my file is package1.json not package.json
Lioness100
Lioness1002y ago
I'm saying that to run node, the file has to be called package.json
Shxdow ツ
Shxdow ツ2y ago
how do I change it I can't right click on the file in vsc
Lioness100
Lioness1002y ago
Please screenshot the file structure on vsc
Lioness100
Lioness1002y ago
this stuff
Photon
Photon2y ago
You are fast in sending 😛
Shxdow ツ
Shxdow ツ2y ago
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
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
Lioness100
Lioness1002y ago
From the name in the package1.json, I'm guessing you followed a guide on youtube or copied code from github?
Shxdow ツ
Shxdow ツ2y ago
yes
Lioness100
Lioness1002y ago
I'd recommend using the official guide, the one I linked above
Shxdow ツ
Shxdow ツ2y ago
how do I change the names of the files though?
Lioness100
Lioness1002y ago
right click them
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
that is the right click box 🤷‍♂️
Lioness100
Lioness1002y ago
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
Lioness100
Lioness1002y ago
not here
Lioness100
Lioness1002y ago
here
Shxdow ツ
Shxdow ツ2y ago
I clicked on one of the files (on the side) I have to go I'll be back later
Lioness100
Lioness1002y ago
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
Krish
Krish2y ago
didn't read everything but I guess you did something wrong in line 2
- require('dotenv/config');
- require('dotenv').config();
- require('dotenv/config');
- require('dotenv').config();
Lioness100
Lioness1002y ago
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)
Krish
Krish2y ago
pepeDaheck
Lioness100
Lioness1002y ago
Nevermind lol, it's been a thing since 2015 idk why I thought it was recent
Krish
Krish2y ago
lol whaaa why is that inside AppData pepeSweat that happens for untrusted folders
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
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 ?
Lioness100
Lioness1002y ago
Run npm i and try again. If that doesn't work, please show your files again like this
Shxdow ツ
Shxdow ツ2y ago
want me to show you the error message I get when I run that?
Lioness100
Lioness1002y ago
Yes
Shxdow ツ
Shxdow ツ2y ago
Lioness100
Lioness1002y ago
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\
Shxdow ツ
Shxdow ツ2y ago
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?
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
ok thanks
Shxdow ツ
Shxdow ツ2y ago
I really appreciate your help so here is the bio of my bot (I will remove if you want).
Shxdow ツ
Shxdow ツ2y ago
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)
Lioness100
Lioness1002y ago
Damn it when did my tag change That's bad news I have #4566 everywhere for instructions on how to reach out to me
Shxdow ツ
Shxdow ツ2y ago
haha lol
Lioness100
Lioness1002y ago
Thanks haha though
Shxdow ツ
Shxdow ツ2y ago
erm
Shxdow ツ
Shxdow ツ2y ago
Lioness100
Lioness1002y ago
Could you run ls?
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
I have worked on this bot for 8+ hours now 😭 💀
Lioness100
Lioness1002y ago
Just out of curiosity, run npm i discord.js
Shxdow ツ
Shxdow ツ2y ago
holy shit it is doing a lot of stuff 💀 done
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
I ran node index.js and here is what it replied with
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
Lioness100
Lioness1002y ago
KEKW did you make index.js a folder and put index.js inside
Shxdow ツ
Shxdow ツ2y ago
yes 💀
Lioness100
Lioness1002y ago
Whatever lol, just run npm i dotenv and it will work As long as the .env file is in there somewhere too
Shxdow ツ
Shxdow ツ2y ago
It is and I did that and then node index.js and it replied with this
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
fixed that error
Lioness100
Lioness1002y ago
Did you add more to your code since this?
Shxdow ツ
Shxdow ツ2y ago
one line but I removed it and now I get this
Shxdow ツ
Shxdow ツ2y ago
Lioness100
Lioness1002y ago
That means that your .env in fact is not "in there" :))
Shxdow ツ
Shxdow ツ2y ago
i'll show you lol
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
this is my index.js file or folder rather
Lioness100
Lioness1002y ago
What's in the .env
Shxdow ツ
Shxdow ツ2y ago
TOKEN=(bot token)
Lioness100
Lioness1002y ago
Oh It's cuz you did process.env1 That's not a thing, it's process.env
Shxdow ツ
Shxdow ツ2y ago
oh fuck me
Lioness100
Lioness1002y ago
What's your thing with ones KEKW
Shxdow ツ
Shxdow ツ2y ago
its a long story lol I forgot I reset the bot token as well hahahahaha lemme fix that and it should hopefully work
Lioness100
Lioness1002y ago
Out of curiosity, are you doing this just to make a bot, or do you want to learn to code too?
Shxdow ツ
Shxdow ツ2y ago
both 😄 we have a problem when I reset the token it just says the same token as before
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
I want to make a bot first, then I will actually learn to code 😅 thank you .
Lioness100
Lioness1002y ago
Like, you reset the token on the discord portal, and when you copy the new one, it's the same?
Shxdow ツ
Shxdow ツ2y ago
yes
Lioness100
Lioness1002y ago
Then just use that one
Shxdow ツ
Shxdow ツ2y ago
but it says invalid token when I paste it in VSC and run node index.js
Lioness100
Lioness1002y ago
Idk how to help you, I guess just make sure you're actually resetting it and you're actually copying the new one
Shxdow ツ
Shxdow ツ2y ago
erm question
Lioness100
Lioness1002y ago
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
Spinel
Spinel2y ago
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.
Lioness100
Lioness1002y ago
Sorry that's a huge block of text But good info
Shxdow ツ
Shxdow ツ2y ago
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)
Lioness100
Lioness1002y ago
Yes But I really doubt the token is "glitched"
Shxdow ツ
Shxdow ツ2y ago
I will try it 😭
Lioness100
Lioness1002y ago
Maybe send a screen recording of this happening to you?
Shxdow ツ
Shxdow ツ2y ago
with the token there? 💀 not a chance
Lioness100
Lioness1002y ago
You can reset it after lol Anyways, whatever works
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
I keeo getting this message -_-
Lioness100
Lioness1002y ago
oh hold up that doesn't mean the token is invalid, that means you're not inputting the token correctly
Shxdow ツ
Shxdow ツ2y ago
I'll show you exactly what I am doing (with a totally fake token) TOKEN=M7innsyI8bsg
Lioness100
Lioness1002y ago
Please send your index.js code again
Shxdow ツ
Shxdow ツ2y ago
const { Client, GatewayIntentBits } = require('discord.js')
require("dotenv").config();

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})
client.on('ready', async () => {
console.log('The bot is ready')
})

client.on('messageCreate', async (message) => {
if (message.content === '/hello') {
message.reply('Hello!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/goodnight') {
message.reply('Goodnight! Sleep tight! Do not let Shxdow bite!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '*ping') {
message.reply('Pong!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '!dev') {
message.reply('The developer of this bot is Shxdowツ#3697')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/invite') {
message.reply('https://discord.com/api/oauth2/authorize?client_id=1061461444698312785&permissions=8&scope=bot%20applications.commands')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/commands') {
message.reply('/hello, /goodnight, *ping, !dev, /invite')
}
})
client.on("ready", async () => {}
,client.login (process.env.TOKEN))
const { Client, GatewayIntentBits } = require('discord.js')
require("dotenv").config();

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})
client.on('ready', async () => {
console.log('The bot is ready')
})

client.on('messageCreate', async (message) => {
if (message.content === '/hello') {
message.reply('Hello!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/goodnight') {
message.reply('Goodnight! Sleep tight! Do not let Shxdow bite!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '*ping') {
message.reply('Pong!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '!dev') {
message.reply('The developer of this bot is Shxdowツ#3697')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/invite') {
message.reply('https://discord.com/api/oauth2/authorize?client_id=1061461444698312785&permissions=8&scope=bot%20applications.commands')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/commands') {
message.reply('/hello, /goodnight, *ping, !dev, /invite')
}
})
client.on("ready", async () => {}
,client.login (process.env.TOKEN))
Lioness100
Lioness1002y ago
bro what the heck is that
Shxdow ツ
Shxdow ツ2y ago
no hate 💀
Lioness100
Lioness1002y ago
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 ablobnod
Shxdow ツ
Shxdow ツ2y ago
the first line you have there was suggested by a person in another server... the second line is to run the env file
Lioness100
Lioness1002y ago
OK, well fix it by replace both of those lines with just client.login (process.env.TOKEN))
Shxdow ツ
Shxdow ツ2y ago
with the space?
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
lol
Lioness100
Lioness1002y ago
but whatever you think looks the best
Shxdow ツ
Shxdow ツ2y ago
I left the server I swear I am not lying I swear ong bro
Lioness100
Lioness1002y ago
I'm just wondering if you royally misunderstood or the person has no idea what they're talking about KEKW
Shxdow ツ
Shxdow ツ2y ago
they put it in `` and told me to copy and paste
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
lol I get the same message I copied what you put and then fixed the errors it told me to fix
Lioness100
Lioness1002y ago
Send me your code again
Shxdow ツ
Shxdow ツ2y ago
const { Client, GatewayIntentBits } = require('discord.js')
require("dotenv").config();

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})
client.on('ready', async () => {
console.log('The bot is ready')
})

client.on('messageCreate', async (message) => {
if (message.content === '/hello') {
message.reply('Hello!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/goodnight') {
message.reply('Goodnight! Sleep tight! Do not let Shxdow bite!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '*ping') {
message.reply('Pong!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '!dev') {
message.reply('The developer of this bot is Shxdowツ#3697')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/invite') {
message.reply('https://discord.com/api/oauth2/authorize?client_id=1061461444698312785&permissions=8&scope=bot%20applications.commands')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/commands') {
message.reply('/hello, /goodnight, *ping, !dev, /invite')
}
})
client.login(process.env.TOKEN);
const { Client, GatewayIntentBits } = require('discord.js')
require("dotenv").config();

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
})
client.on('ready', async () => {
console.log('The bot is ready')
})

client.on('messageCreate', async (message) => {
if (message.content === '/hello') {
message.reply('Hello!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/goodnight') {
message.reply('Goodnight! Sleep tight! Do not let Shxdow bite!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '*ping') {
message.reply('Pong!')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '!dev') {
message.reply('The developer of this bot is Shxdowツ#3697')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/invite') {
message.reply('https://discord.com/api/oauth2/authorize?client_id=1061461444698312785&permissions=8&scope=bot%20applications.commands')
}
})
client.on('messageCreate', async (message) => {
if (message.content === '/commands') {
message.reply('/hello, /goodnight, *ping, !dev, /invite')
}
})
client.login(process.env.TOKEN);
can I friend request you? you literally are such a relief
Lioness100
Lioness1002y ago
Sure
Shxdow ツ
Shxdow ツ2y ago
ty
Lioness100
Lioness1002y ago
can you screenshot the error again? Just so I can make sure it's exactly the same
Shxdow ツ
Shxdow ツ2y ago
I am having trouble lining it up to perfectly fit so here it is in text
PS C:\Users\kodel\shxdow-bot> node index.js
C:\Users\kodel\node_modules\discord.js\src\client\Client.js:214
if (!token || typeof token !== 'string') throw new DiscordjsError(ErrorCodes.TokenInvalid);
^

Error [TokenInvalid]: An invalid token was provided.
at Client.login (C:\Users\kodel\node_modules\discord.js\src\client\Client.js:214:52)
at Object.<anonymous> (C:\Users\kodel\shxdow-bot\index.js\index.js:45:8)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'TokenInvalid'
}
PS C:\Users\kodel\shxdow-bot> node index.js
C:\Users\kodel\node_modules\discord.js\src\client\Client.js:214
if (!token || typeof token !== 'string') throw new DiscordjsError(ErrorCodes.TokenInvalid);
^

Error [TokenInvalid]: An invalid token was provided.
at Client.login (C:\Users\kodel\node_modules\discord.js\src\client\Client.js:214:52)
at Object.<anonymous> (C:\Users\kodel\shxdow-bot\index.js\index.js:45:8)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'TokenInvalid'
}
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
💀 I might have a fix hold up nvrm I figured if I added var in front it might work but no
Lioness100
Lioness1002y ago
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
Shxdow ツ
Shxdow ツ2y ago
🎉 I wasn't going to either way hahahaha put ' or no?
Lioness100
Lioness1002y ago
yes
Shxdow ツ
Shxdow ツ2y ago
'token'
Lioness100
Lioness1002y ago
all strings need to have quotes around them
Shxdow ツ
Shxdow ツ2y ago
inside () lol
Lioness100
Lioness1002y ago
I wasn't joking lol
Shxdow ツ
Shxdow ツ2y ago
that is why it wasn't working before I didn't have '' around the token after TOKEN: I had TOKEN=ndhua7**&^jy
Lioness100
Lioness1002y ago
ah
Shxdow ツ
Shxdow ツ2y ago
it should be TOKEN:'jshyujsgjh' yes?
Lioness100
Lioness1002y ago
the quotes don't apply for .env
Shxdow ツ
Shxdow ツ2y ago
oh lol
Lioness100
Lioness1002y ago
Also it's a "=", not ":"
Shxdow ツ
Shxdow ツ2y ago
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
Shxdow ツ
Shxdow ツ2y ago
Shxdow ツ
Shxdow ツ2y ago
help meh Lioness 😭
Lioness100
Lioness1002y ago
easy fix
Shxdow ツ
Shxdow ツ2y ago
?
Lioness100
Lioness1002y ago
go to discord developer portal, bot tab, scroll down and make sure message content is checked
Shxdow ツ
Shxdow ツ2y ago
🤭 I LOVE YOU
Shxdow ツ
Shxdow ツ2y ago
Lioness100
Lioness1002y ago
follow me on github Kappa
Shxdow ツ
Shxdow ツ2y ago
I don't have a github acc 🤣
Lioness100
Lioness1002y ago
you'll never make it as a developer without a github account ablobheadshake one and then follow me ablobnod
Shxdow ツ
Shxdow ツ2y ago
ok erm question how do I add a custom status?
Lioness100
Lioness1002y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Shxdow ツ
Shxdow ツ2y ago
ty ❤️
Lioness100
Lioness1002y ago
you should put that code in the ready event
Shxdow ツ
Shxdow ツ2y ago
what is the ready event? 💀
Lioness100
Lioness1002y ago
(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')
})
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')
})
client.on('ready', async () => {
console.log('this code is in here')
console.log('The bot is ready')
})
Shxdow ツ
Shxdow ツ2y ago
ok so the code to add the custom status is 'this code is in here'?
Lioness100
Lioness1002y ago
no that's a console.log function, which logs strings or objects or things to the terminal
Shxdow ツ
Shxdow ツ2y ago
right so put my whole code in the console? 💀
Lioness100
Lioness1002y ago
no, that was just an example line of code
Shxdow ツ
Shxdow ツ2y ago
lol
Lioness100
Lioness1002y ago
client.on('ready', async () => {
client.user.setStatusOrWhaterveraefhdn()
console.log('The bot is ready')
})
client.on('ready', async () => {
client.user.setStatusOrWhaterveraefhdn()
console.log('The bot is ready')
})
Shxdow ツ
Shxdow ツ2y ago
I can't type in the terminal now @Lioness100 sorry for ping -_-
Lioness100
Lioness1002y ago
that's because the bot process is running
Shxdow ツ
Shxdow ツ2y ago
how do I stop it?
Lioness100
Lioness1002y ago
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+`
Shxdow ツ
Shxdow ツ2y ago
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)
Krish
Krish2y ago
pepeHmm