Discord Bot ERROR (FIX)

Status
This thread has been locked.

DZNJOSEPH

Banned
Feedback score
0
Posts
28
Reactions
12
Resources
0
unknown.png
Hello,

Recently i've been learning how to develop discord bots and i'm
having a few errors within the bot i'm trying to make at the moment.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Function

Minecraft Plugin Developer
Supreme
Feedback score
38
Posts
938
Reactions
332
Resources
0
Well first things first, you aren't even ending your event listeners. Secondly, on line 12 you are missing a ) and you added an ) on line 13, and inside of an if statement you can not check if it does not match your first if statement.

Edit: And, you are not logging in your discord bot. You can do this via
Code:
Client#login(String token)
[DOUBLEPOST=1604538314][/DOUBLEPOST]Also, not trying to be mean but before you try learning how to make discord bots in javascript, I advise you actually learn javascript first.
 
Last edited:

Derock

Bot Developer
Supreme
Feedback score
1
Posts
103
Reactions
40
Resources
0
Quick tip, I would recommend learning JavaScript basics or follow a tutorial when making your first bots.

There are a few things wrong with your code.
I'm going to break down the code you have written.

Line 1: `const discord = require('discord.js');`
In this line, you declare a variable named `discord`.
const means constant, and after the const is the variable name, which in this case is discord.
= means equal.
require() is a function, basically meaning import.
You're importing a library named discord.js, which is inside of quotes inside parenthesis.
You usually use () when calling a function.

So far you have a variable named discord that imports the discord library.

Line 2: First half is the same as last time, except this time the variable is named client.
You set it equal to `new discord.Client()`
Using the `new` keyword is used when creating a new instance of a class. In this case, you are creating a new instance of a `discord.Client`

Line 4: You import your `config.json` using the same principle as line 1.

Line 6:
client.login is a function, but you are missing your `()`
client.login is a method that is part of the Discord client. Read more here
Another thing you do wrong here is you capitalize the C in config.
In the previous line when you import the config, you put a lowercase c in the variable name (after the const and before the =)
The correct version of that line would be: `client.login(config.token);`

Line 8: client.on() is a method from EventEmitter, since the Client class extends BaseClient which extends EventEmitter.
client.on() takes in two arguments, the first one is an event name, and the second one is a function that is executed when the event is triggered.
Arguments are basically variables you pass into a function, like this: `client.on(event, callback)`
One thing you fail to do is close your arrow function.

Arrow functions start like: () => {
and close like: }

An example of a proper arrow function would be:

Code:
() => {
    console.log('foo');
}


So on line 8 and 9 you have this:
Code:
() => {
    console.log(client.user.username + " has logged in.");
And from that, you can see you are missing the close to it.
After the `}` you also need a `)` because this is all inside of the EventEmiter.on method.

All functions can be called like: `functionName(args)`
args being any arguments you want to pass in.

Line 12: Proper syntax for the if statement is: `if(condition) { something }`
Where something is what you want to do, and the condition is the condition that must be true for something to run.
Alternatively, if you only need to do one thing after an if, you can do `if(condition) something`

So on line 12, you are missing a `)` before the return statement.

Line 13: You have an if statement, but you close it too early. You put the `)` before you finished the condition. You actually did it twice.
The && operator means both sides must be true.
The first half of your condition is `message.content.toLowerCase` which is a function, so you would need `message.content.toLowerCase()`
In the second half, you check if the channel id is equal to the one provided, so that part is fine.

You start out the rest of the if statement with a `{`, but again forgot the `}` to close it.
Same thing with line 14, where you have your else statement and have a `{` but another missing `}`

The summary I just gave scratches the surface of javascript and doesn't have too much detail. I highly recommend watching videos and start simple, with stuff like a basic ping command, and then advancing further.

If you ever need help with code, feel free to join my coding discord server where I frequently answer questions. https://discord.gg/P9q5hHs8Ge

I spent way too much time writing this.
 
Last edited:

Ty

Supreme
Feedback score
28
Posts
790
Reactions
497
Resources
2
no way do u have discord bot developer in ur title when u can't even write javascript loooool
 

StackFlow

Feedback score
1
Posts
82
Reactions
45
Resources
0
I mean either way helping him out rather than trashing the thread is a much better approach like Derock did. The same can be said for many people that claim to be "developers" but actually aren't. Sometimes taking a hands-on approach rather than learning every single bit of a language is much better since a lot of the stuff you usually learn is total garbage and you will not use in the real world.
 

Ty

Supreme
Feedback score
28
Posts
790
Reactions
497
Resources
2
I mean either way helping him out rather than trashing the thread is a much better approach like Derock did. The same can be said for many people that claim to be "developers" but actually aren't. Sometimes taking a hands-on approach rather than learning every single bit of a language is much better since a lot of the stuff you usually learn is total garbage and you will not use in the real world.
Don't claim to be something you aren't, it's that simple ;)
 

WilddWolf

Feedback score
1
Posts
40
Reactions
8
Resources
0
Hi there,

I run a hosting company with many developers on our support team.

We would love to help you get your bot working. With over 22+ years of combined experience, we know what we are doing.

Join our Discord and open a ticket - https://neytiri.digital/discord
 
Status
This thread has been locked.
Top