I really would appreciate someone showing me how to make a discord bot, because I am really stuck an

I really would appreciate someone showing me how to make a discord bot, because I am really stuck and I tried like so many tutorials on youtube and still can't get it
77 Replies
d.js toolkit
d.js toolkit11mo ago
- 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 staff
IcyPickle
IcyPickle11mo ago
if you're using this server for help / whatever you need some basic knowledge of node.js we can't teach yuh javascript from the ground up sorry sadbob
Fisch
FischOP11mo ago
Isn't it like basic to do a discord bot? But alright
IcyPickle
IcyPickle11mo ago
if you have some basic knowledge i'm happy to help what can't you get running in the code ?
Fisch
FischOP11mo ago
Well whenever I use the command: node index.js it just says that the path wasn't found, or just says nothing
IcyPickle
IcyPickle11mo ago
show me the code and the whole error
Fisch
FischOP11mo ago
I'm not getting any errors right now somehow, but the bot still isn't starting
IcyPickle
IcyPickle11mo ago
show me the code?
Fisch
FischOP11mo ago
node:internal/modules/cjs/loader:1147 throw err; ^ Error: Cannot find module 'C:\Users\win 10\OneDrive\Desktop\FB\bot.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15) at Module._load (node:internal/modules/cjs/loader:985:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'MODULE_NOT_FOUND', requireStack: [] } Node.js v20.10.0 Got an error
IcyPickle
IcyPickle11mo ago
erm... is your file name index.js?
Fisch
FischOP11mo ago
const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const PREFIX = '!'; // You can change this to your desired command prefix client.once('ready', () => { console.log('Bot is online!'); }); client.on('messageCreate', (message) => { if (message.author.bot) return; // Ignore messages from other bots // Check if the message starts with the command prefix and is from a guild (server) if (message.content.startsWith(PREFIX) && message.guild) { const args = message.content.slice(PREFIX.length).trim().split(/ +/); const command = args.shift().toLowerCase(); // Check if the command is '!greet' if (command === 'greet') { // Reply with a greeting message.reply('Hello! I am your friendly Discord bot.'); } } }); // Log in to Discord with your bot token client.login('Bot token'); Yes Here is the code I mean I just didn't show the token
IcyPickle
IcyPickle11mo ago
yuh try renaming the file to bot.js
Fisch
FischOP11mo ago
Well it's like index It just doesn't say anything It doesn't start
IcyPickle
IcyPickle11mo ago
are you using discord.js v14 or v13 ?
Fisch
FischOP11mo ago
14
IcyPickle
IcyPickle11mo ago
... wait here
Fisch
FischOP11mo ago
Why
IcyPickle
IcyPickle11mo ago
const { Client, IntentsBitField, Events} = require('discord.js');
const { Client, IntentsBitField, Events} = require('discord.js');
Fisch
FischOP11mo ago
Yes
IcyPickle
IcyPickle11mo ago
copy this instead of your normal require
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent
],
});
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent
],
});
and make this your client
Fisch
FischOP11mo ago
How
IcyPickle
IcyPickle11mo ago
replace "messageCreate" with Events.MessageCreate too what do you mean how? replace const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); with this
Fisch
FischOP11mo ago
Did it
IcyPickle
IcyPickle11mo ago
now replace "messageCreate" with Events.MessageCreate
Fisch
FischOP11mo ago
Already did that
IcyPickle
IcyPickle11mo ago
now run the bot it should work
Fisch
FischOP11mo ago
Nothing changed I wrote: node bot.js
IcyPickle
IcyPickle11mo ago
..... it's node .
Fisch
FischOP11mo ago
And nothing changed somehow
IcyPickle
IcyPickle11mo ago
.... it's node . write node .
Fisch
FischOP11mo ago
Sorry
IcyPickle
IcyPickle11mo ago
does it work now?
Fisch
FischOP11mo ago
Well I got an error that the module was wrong, so I changed it back And then I ran the command and it said nothing
IcyPickle
IcyPickle11mo ago
spam ctrl + y in your code and it should go back or ctrl + z
Fisch
FischOP11mo ago
How much Should I go back
IcyPickle
IcyPickle11mo ago
until it goes back to where you changed the things i told you to change
Fisch
FischOP11mo ago
I mean I changed the name of the file Not the things in it
IcyPickle
IcyPickle11mo ago
ohhh
Fisch
FischOP11mo ago
Then it said that node:internal/modules/cjs/loader:452 throw err; ^ Error: Cannot find module 'C:\Users\win 10\OneDrive\Desktop\FB\index.js'. Please verify that the package.json has a valid "main" entry at tryPackage (node:internal/modules/cjs/loader:444:19) at Module._findPath (node:internal/modules/cjs/loader:715:18) at resolveMainPath (node:internal/modules/run_main:26:23) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:24) at node:internal/main/run_main_module:28:49 { code: 'MODULE_NOT_FOUND', path: 'C:\Users\win 10\OneDrive\Desktop\FB\package.json', requestPath: 'C:\Users\win 10\OneDrive\Desktop\FB'
IcyPickle
IcyPickle11mo ago
then just make it index.js again
Fisch
FischOP11mo ago
Did that before
IcyPickle
IcyPickle11mo ago
do it again then
Fisch
FischOP11mo ago
Then it said nothing
axiprime
axiprime11mo ago
If you dont know much I would recommend to learn discord JS 14. There is guide that can make you set it up from scratch. https://discordjs.guide/#before-you-begin
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Fisch
FischOP11mo ago
Did it
IcyPickle
IcyPickle11mo ago
🙏
Fisch
FischOP11mo ago
Sorry
IcyPickle
IcyPickle11mo ago
the bot is working then test it you do have the bot in a server right?
Fisch
FischOP11mo ago
Yes
IcyPickle
IcyPickle11mo ago
okay test the bot
axiprime
axiprime11mo ago
Also, you should now devving from onedrive, put it locally at least.
Fisch
FischOP11mo ago
It doesn't work, but I don't wanna waste your time, but thanks
axiprime
axiprime11mo ago
What doesnt work ? there is still a path issue ?
Fisch
FischOP11mo ago
No, the bot just isn't on
axiprime
axiprime11mo ago
What is your discord js version ?
Fisch
FischOP11mo ago
14
axiprime
axiprime11mo ago
Your intent are wrong then
Fisch
FischOP11mo ago
Why?
IcyPickle
IcyPickle11mo ago
i told him to replace them he did atleast i think he did
axiprime
axiprime11mo ago
You also have to enable message content intent in the portal for messageCreate.
Fisch
FischOP11mo ago
const { Client, IntentsBitField, Events} = require('discord.js'); const client = new Client({ intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.MessageContent ], }); const PREFIX = '!'; // You can change this to your desired command prefix client.once('ready', () => { console.log('Bot is online!'); }); client.on('messageCreate', (message) => { if (message.author.bot) return; // Ignore messages from other bots // Check if the message starts with the command prefix and is from a guild (server) if (message.content.startsWith(PREFIX) && message.guild) { const args = message.content.slice(PREFIX.length).trim().split(/ +/); const command = args.shift().toLowerCase(); // Check if the command is '!greet' if (command === 'greet') { // Reply with a greeting message.reply('Hello! I am your friendly Discord bot.'); } } }); // Log in to Discord with your bot token client.login(''); It looks like this now
axiprime
axiprime11mo ago
doesnt we use GatewayIntentBits in V14 ?
axiprime
axiprime11mo ago
No description
axiprime
axiprime11mo ago
I guess both working.
IcyPickle
IcyPickle11mo ago
yuh
axiprime
axiprime11mo ago
What error you get from starting ? How do you start your bot?
Fisch
FischOP11mo ago
?? With node .
IcyPickle
IcyPickle11mo ago
@zSuperSlammer did you save your script ? ctrl + s
Fisch
FischOP11mo ago
Did it now
IcyPickle
IcyPickle11mo ago
ok test the bot
Fisch
FischOP11mo ago
I tested the bot, but it didn't change anything
axiprime
axiprime11mo ago
What the error
IcyPickle
IcyPickle11mo ago
oh i forgot
Fisch
FischOP11mo ago
It's on Thank you so much guys
IcyPickle
IcyPickle11mo ago
@zSuperSlammer replace 'ready' with IntentsBitField.ClientReady nvm ig np
Fisch
FischOP11mo ago
I don't how to thank you man
IcyPickle
IcyPickle11mo ago
it's the slightest i can do dw about it
Want results from more Discord servers?
Add your server