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