Hey everyone, I'm mitch.
I'm here to teach you how to make a basic discord bot in JavaScript!
First off you're going to have to make a new
discord application.
You can name this anything you want.
After creating your discord application, you'll be taken to this screen.
On the left side of your screen choose bot.
Ok, We're done with creating our bot account!
Now, even though you can use notepad to edit javascript I'd recommend getting an IDE (Integrated Development Environment). I use
Visual Studio Code. You can also use other text editors such as
Notepad++.
Alright! The last thing we have to do is get
Node.js. When installing this, make sure to "Add To PATH".
Now time to install
Discord.js, The module that will allow us to interact with Discord's API!
Make a new folder in anywhere you want, I'll use my desktop! Inside this folder, we're going to hold down SHIFT and RIGHT-CLICK. It should bring up a drop-down menu, like this.
Press "Open PowerShell window here". If there is no option for this, Take a look for "Open Command Prompt window here". If none of these options are available. Goto Command Prompt (or Terminal) and find where your file is, I put mine on the desktop so I'll type "cd Desktop\bot". Once you are here you can type node -v and npm -v to check if you have Node installed. After you know you have Node installed you can type "npm install discord.js". Let that install, once it's done you can exit command prompt!
Now we're going to create the file where all our bots code will be stored! RIGHT-CLICK in the folder where you want your bot to be created.
Rename that file you just created to "bot.js" and make sure there is no .txt extension on the end.
If you can't see file extensions then do what is shown in the image below.
If you can see file extensions and renaming the file to bot.js worked for you, you can skip the above step.
RIGHT-CLICK this file and if you can see open with Notepad++ or Visual Studio Code, open it with those. If not search for one of them and open the one you searched for. After opening one of them press CTRL + O and find your bot.js file in the folder you created it in.
Once you're inside we can finally start typing up our base code!
javascript code:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('ready', () => {
console.log('Once the bot is ready this message will show!');
});
bot.on('message', async (message) => {
console.log('A message was sent');
});
bot.login(TOKEN);
Where you see "TOKEN" we're going to have to go to our bot account again. You're going to want to press copy on this page. If you can't find your way here, refer to the other steps.
After copying this you can come back to your code and copy paste it where I have put "TOKEN". Once you have done this your bot is ready to go!
Time to add it to your discord server for testing! Let's get our invite link.
Once you've done this, paste it into your browser and select your server here.
Once that's done go to the Command Prompt again and find the folder where your bot.js is. After that, type "node bot.js". This will start your bot, check the Discord server your bot is in and it should be online! Try sending a message and checking your console. It should say "A message was sent". If not, either my tutorial was garbage or you messed something up. Try recreating the steps, or posting on this thread for help.
Take a look at the
Discord.js Documentation.
Module - a module is a part of a program. Programs are composed of one or more independently developed modules that are not combined until the program is linked. A single module can contain one or several routines.
IDE - a software application that provides comprehensive facilities to computer programmers for software development.
Documentation - the information that describes the product to its users. It consists of the product technical manuals and online information (including online versions of the technical manuals and help facility descriptions).
Please post any CnC below.