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

125 messages · Page 1 of 1 (latest)

solid owl
#

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

lofty otterBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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
ornate pike
#

we can't teach yuh javascript from the ground up sorry sadbob

solid owl
#

But alright

ornate pike
#

what can't you get running in the code

#

?

solid owl
ornate pike
#

show me the code and the whole error

solid owl
ornate pike
#

show me the code?

solid owl
#

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

ornate pike
#

erm...

#

is your file name

#

index.js?

solid owl
#

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');

solid owl
solid owl
#

I mean I just didn't show the token

ornate pike
#

yuh

#

try renaming the file

#

to bot.js

solid owl
#

Well it's like index

#

It just doesn't say anything

#

It doesn't start

ornate pike
#

are you using discord.js v14 or v13

#

?

solid owl
#

14

ornate pike
#

...

#

wait here

solid owl
#

Why

ornate pike
#
const { Client, IntentsBitField, Events} = require('discord.js');
solid owl
#

Yes

ornate pike
#

copy this instead of your normal require

#
const client = new Client({
  intents: [
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMembers,
    IntentsBitField.Flags.GuildMessages,
    IntentsBitField.Flags.MessageContent
  ],
});```
#

and make this your client

solid owl
#

How

ornate pike
#

replace "messageCreate" with Events.MessageCreate too

ornate pike
#

replace const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

solid owl
#

Did it

ornate pike
#

now replace "messageCreate" with Events.MessageCreate

solid owl
#

Already did that

ornate pike
#

now run the bot

#

it should work

solid owl
#

Nothing changed

#

I wrote: node bot.js

ornate pike
#

.....

#

it's node .

solid owl
#

And nothing changed somehow

ornate pike
#

....

#

it's node .

#

write

#

node .

solid owl
#

Sorry

ornate pike
#

does it work now?

solid owl
#

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

ornate pike
#

and it should go back

#

or ctrl + z

solid owl
#

How much

#

Should I go back

ornate pike
#

until it goes back to where you changed the things i told you to change

solid owl
#

I mean I changed the name of the file

#

Not the things in it

ornate pike
#

ohhh

solid owl
#

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'

ornate pike
#

then just make it index.js again

solid owl
#

Did that before

ornate pike
#

do it again then

solid owl
#

Then it said nothing

halcyon musk
solid owl
#

Did it

solid owl
#

Sorry

ornate pike
#

test it

#

you do have the bot in a server right?

solid owl
#

Yes

ornate pike
#

okay test the bot

halcyon musk
#

Also, you should now devving from onedrive, put it locally at least.

solid owl
halcyon musk
solid owl
#

No, the bot just isn't on

halcyon musk
#

What is your discord js version ?

solid owl
#

14

halcyon musk
#

Your intent are wrong then

solid owl
#

Why?

ornate pike
#

he did

#

atleast i think he did

halcyon musk
#

You also have to enable message content intent in the portal for messageCreate.

solid owl
#

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

halcyon musk
#

doesnt we use GatewayIntentBits in V14 ?

#

I guess both working.

ornate pike
halcyon musk
#

What error you get from starting ?

#

How do you start your bot?

solid owl
#

With node .

ornate pike
#

@solid owl did you save your script

#

?

#

ctrl + s

solid owl
#

Did it now

ornate pike
#

ok test the bot

solid owl
#

I tested the bot, but it didn't change anything

halcyon musk
#

What the error

ornate pike
#

oh

#

i forgot

solid owl
#

It's on

#

Thank you so much guys

ornate pike
#

@solid owl replace 'ready' with IntentsBitField.ClientReady

ornate pike
#

np

solid owl
#

I don't how to thank you man

ornate pike
#

it's the slightest i can do dw about it