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 toolkit12mo 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
IcyPickle12mo 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
FischOP12mo ago
Isn't it like basic to do a discord bot? But alright
IcyPickle
IcyPickle12mo ago
if you have some basic knowledge i'm happy to help what can't you get running in the code ?
Fisch
FischOP12mo ago
Well whenever I use the command: node index.js it just says that the path wasn't found, or just says nothing
IcyPickle
IcyPickle12mo ago
show me the code and the whole error
Fisch
FischOP12mo ago
I'm not getting any errors right now somehow, but the bot still isn't starting
IcyPickle
IcyPickle12mo ago
show me the code?
Fisch
FischOP12mo 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
IcyPickle12mo ago
erm... is your file name index.js?
Fisch
FischOP12mo 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
IcyPickle12mo ago
yuh try renaming the file to bot.js
Fisch
FischOP12mo ago
Well it's like index It just doesn't say anything It doesn't start
IcyPickle
IcyPickle12mo ago
are you using discord.js v14 or v13 ?
Fisch
FischOP12mo ago
14
IcyPickle
IcyPickle12mo ago
... wait here
Fisch
FischOP12mo ago
Why
IcyPickle
IcyPickle12mo ago
const { Client, IntentsBitField, Events} = require('discord.js');
const { Client, IntentsBitField, Events} = require('discord.js');
Fisch
FischOP12mo ago
Yes
IcyPickle
IcyPickle12mo 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
FischOP12mo ago
How
IcyPickle
IcyPickle12mo 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
FischOP12mo ago
Did it
IcyPickle
IcyPickle12mo ago
now replace "messageCreate" with Events.MessageCreate
Fisch
FischOP12mo ago
Already did that
IcyPickle
IcyPickle12mo ago
now run the bot it should work
Fisch
FischOP12mo ago
Nothing changed I wrote: node bot.js
IcyPickle
IcyPickle12mo ago
..... it's node .
Fisch
FischOP12mo ago
And nothing changed somehow
IcyPickle
IcyPickle12mo ago
.... it's node . write node .
Fisch
FischOP12mo ago
Sorry
IcyPickle
IcyPickle12mo ago
does it work now?
Fisch
FischOP12mo 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
IcyPickle12mo ago
spam ctrl + y in your code and it should go back or ctrl + z
Fisch
FischOP12mo ago
How much Should I go back
IcyPickle
IcyPickle12mo ago
until it goes back to where you changed the things i told you to change
Fisch
FischOP12mo ago
I mean I changed the name of the file Not the things in it
IcyPickle
IcyPickle12mo ago
ohhh
Fisch
FischOP12mo 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
IcyPickle12mo ago
then just make it index.js again
Fisch
FischOP12mo ago
Did that before
IcyPickle
IcyPickle12mo ago
do it again then
Fisch
FischOP12mo ago
Then it said nothing
axiprime
axiprime12mo 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
FischOP12mo ago
Did it
IcyPickle
IcyPickle12mo ago
🙏
Fisch
FischOP12mo ago
Sorry
IcyPickle
IcyPickle12mo ago
the bot is working then test it you do have the bot in a server right?
Fisch
FischOP12mo ago
Yes
IcyPickle
IcyPickle12mo ago
okay test the bot
axiprime
axiprime12mo ago
Also, you should now devving from onedrive, put it locally at least.
Fisch
FischOP12mo ago
It doesn't work, but I don't wanna waste your time, but thanks
axiprime
axiprime12mo ago
What doesnt work ? there is still a path issue ?
Fisch
FischOP12mo ago
No, the bot just isn't on
axiprime
axiprime12mo ago
What is your discord js version ?
Fisch
FischOP12mo ago
14
axiprime
axiprime12mo ago
Your intent are wrong then
Fisch
FischOP12mo ago
Why?
IcyPickle
IcyPickle12mo ago
i told him to replace them he did atleast i think he did
axiprime
axiprime12mo ago
You also have to enable message content intent in the portal for messageCreate.
Fisch
FischOP12mo 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
axiprime12mo ago
doesnt we use GatewayIntentBits in V14 ?
axiprime
axiprime12mo ago
No description
axiprime
axiprime12mo ago
I guess both working.
IcyPickle
IcyPickle12mo ago
yuh
axiprime
axiprime12mo ago
What error you get from starting ? How do you start your bot?
Fisch
FischOP12mo ago
?? With node .
IcyPickle
IcyPickle12mo ago
@zSuperSlammer did you save your script ? ctrl + s
Fisch
FischOP12mo ago
Did it now
IcyPickle
IcyPickle12mo ago
ok test the bot
Fisch
FischOP12mo ago
I tested the bot, but it didn't change anything
axiprime
axiprime12mo ago
What the error
IcyPickle
IcyPickle12mo ago
oh i forgot
Fisch
FischOP12mo ago
It's on Thank you so much guys
IcyPickle
IcyPickle12mo ago
@zSuperSlammer replace 'ready' with IntentsBitField.ClientReady nvm ig np
Fisch
FischOP12mo ago
I don't how to thank you man
IcyPickle
IcyPickle12mo ago
it's the slightest i can do dw about it
Want results from more Discord servers?
Add your server