people playing: 94, servers online: 21, games played: 144,338,133 Top Player: Gentleman

  Toribash Community » Help » Tutorials
Register FAQ General Rules Community
Reply
 
Thread Tools Display Modes
Old Jan 12, 2019   #1
mitch
NON-EXISTING!
 
Members Only Belt
Join Date: Sep 2014
Posts: 1,370



[TBA] | Creating a Discord bot
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.

1



You can name this anything you want.

After creating your discord application, you'll be taken to this screen.

2



On the left side of your screen choose bot.

3



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".

4



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.

5



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.

6



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.

7



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.

8



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.

9



Once you've done this, paste it into your browser and select your server here.

10



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.

Terminology Used



Please post any CnC below.

Last edited by mitch; Jan 13, 2019 at 08:36 PM..
mitch is offline   Reply With Quote
Old Jan 13, 2019   #2
Nation
Senior Member
 
6th Dan Black Belt
Join Date: Apr 2017
Posts: 810
Clan: zero



Works How its meant to
Not had any problems as of yet
Tho the Thing of It disapeering After a few seconds
Can be a bit annoying At times
Otherwise it works well
Nation is offline   Reply With Quote
Old Jan 13, 2019   #3
mitch
NON-EXISTING!
 
Members Only Belt
Join Date: Sep 2014
Posts: 1,370



What disappears after a few seconds?

Are you talking about my discord bot? If so this is the wrong thread...
mitch is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:23 PM.




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
ragdoll fighting game physics fighting game ragdoll fighting physics funmotion joints martial arts karate pc mac free game turn based game