How to make a Discord bot - Globebusinesscenter

Breaking

Home Top Ad

Wednesday, November 13, 2019

How to make a Discord bot

How to make a Discord bot


Discord is something beyond a basic chat service, unlike your favorite MMORPG, where even just uttering the word "bot" may cause you problems, Discord bots are an integral and traditional part of its appeal. They can do many tasks, 

How to make a Discord bot
How to make a Discord bot


Such as accepting donations and spying out application forms for potential moderators, through full-fledged assistants. There is already a fabulous world of Discord robots, but if you're looking for something more specific, we'll explain in detail how to make a Discord bot in this article

How to make a discord bot Step 1: Download Node.js and set up a Discord account if you haven’t

Node.js is a JavaScript runtime that is free and open-source, and you'll require it to really make your bot, uh, work. Download it at nodejs.org and introduce it before you begin on whatever else. 

Clearly, you'll likewise require a Discord account, and your own server to use to test your bot. In the event that you haven't made one yet, go to Discordapp.com and make one. On the off chance that you do have one, sign in to your record and open up the server wherein you need your bot to live. 

You'll additionally require a content management program, like Notepad++ on Windows, to code with.

How to make a discord bot Step 2: make a discord bot

Presently you'll have to make an "application" on Discord to make your bot work. This takes a touch of doing, yet it's not very mind-boggling. The objective here is to get an "approval token" for the bot so Discord perceives your code and includes it to the bot its servers. 

To begin with, head to discordapp.com/designers/applications/me. Your record ought to be signed in, so you'll go directly to your record's rundown of utilizations. Hit New Application to begin. Give the bot a name, at that point hit the catch checked Save Changes. 

Presently, on the right-hand menu, click Bot. Once in the new menu, click Add Bot under the Build-a-bot alternative. On the off chance that you just have one application — the one we simply made — it ought to show up consequently. Something else, select it.

How to make a Discord bot
How to make a Discord bot


How to make a discord bot Step 3: Get your bot’s authorization token


In the container stamped App Bot User, search for the words Token: Click to uncover. Snap that connection and you'll uncover a string of content. That is your bot's approval token, which enables you to send it code. Try not to impart it to anybody — that token permits whoever has it to make code for the bot, which implies whoever has it can control your bot. In the event that you think the token has been undermined, fortunately, you can undoubtedly create another one with the connection directly under the token, which peruses "Produce another token."

How to make a discord bot Step 4: Send your bot to your server


Finally, scroll up to the box marked App Details and find your Client ID, a long number. Copy the number and add it to this URL, in the place of word CLIENTID.

  • https://discordapp.com/oauth2/authorize?&client_id=CLIENTID&scope=bot&permissions=8

The final URL should look like this, but with your client ID number in it instead of this fake one:

  • https://discordapp.com/oauth2/authorize?&client_id=000000000000000001&scope=bot&permissions=8
Duplicate the URL with your customer ID number in it into your program. That will take you to a site where you can reveal to Discord where to send your bot. You'll realize it worked in the event that you open Discord in an application or in your program and explore to your server. The channel will say a bot has joined the room, and you'll see it on the correct side menu under the rundown of online individuals.

How to make a discord bot Step 5: Create a “Bot” folder on your computer


While you're doing that, you can likewise pause for a minute to make an organizer in a simple to-arrive at the place on your PC where you can store all your bot's documents. Call it something straightforward, as "DiscordBot" or "MyBot" so you know precisely what it is.

How to make a discord bot Step 6: Open your text editor and make your bot’s files


You’re going to create three files for your bot from your text editor. In the first, paste this code:

{
“token”: “Your Bot Token”
}
Supplant "Your Bot Token" with the token you created before on your bot's application page. Ensure the token is inside the quotes. At that point spare the record into the Discord bot organizer you made on your work area, utilizing the filename "auth.json." Remember not to spare it as a .txt document — it won't work if it's .txt rather than .json.


How to make a Discord bot
How to make a Discord bot


Make a new file, and put in this code:

{
“name”: “greeter-bot”,
“version”: “1.0.0”,
“description”: “My First Discord Bot”,
“main”: “bot.js”,
“author”: “Your Name”,
“dependencies”: {}
}

Supplant the creator name with your name on the off chance that you need; you can likewise change the "portrayal" to an option that is other than "My First Discord Bot" on the off chance that you need something more in accordance with what you're making, which will be convenient for recalling what your bot should do. 

Spare this record as "package.json" in your Discord bot folder

How to make a discord bot Step 7: Define your bot’s code


There's one more content document to make, and this is the significant one that controls your bot's conduct. You'll need to be acquainted with JavaScript to truly have full control of your bot and realize what you're doing, yet in case you're new to coding and simply need to make something, you can reorder this code into the document to make a basic bot that will welcome you in your server. 

Because of Medium client Renemari Padillo, whose bot instructional exercise helped us make this one. Look at his instructional exercise for code investigating and other exhortations.

var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
    colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});
bot.on('ready', function (evt) {
    logger.info('Connected');
    logger.info('Logged in as: ');
    logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
    // Our bot needs to know if it will execute a command
    // It will listen for messages that will start with `!`
    if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];
       
        args = args.splice(1);
        switch(cmd) {
            // !ping
            case 'ping':
                bot.sendMessage({
                    to: channelID,
                    message: 'Pong!'
                });
            break;
            // Just add any case commands if you want to..
         }
     }
});

This code sets up a Discord bot that will react to specific messages: Specifically, anything that starts with a "!" character. Specifically, we're customizing the bot to react to the direction "!introduction", so on the off chance that anybody types that in your server while the bot is in it, the bot will react with a modified message. In our code, we characterized the message as "Welcome! Welcome to the server!" You can change both the brief message and the reaction message by reclassifying them in the code above. Simply make a point to keep up the single quotes around the messages.

How to create a discord bot Step 8: Open your computer’s “Command Prompt” and navigate to your Discord bot folder


On a Windows PC, you can without much of a stretch get to the Command Prompt by tapping the Windows symbol and composing "Order Prompt" in the field. When it's open, type "compact disc" trailed by the document way to your organizer. On my PC, the order resembles this present: "cdUsersPhil's DesktopDesktopDiscordBot". That should change the direction brief line to incorporate the document way to your organizer. 

On the other hand, you can explore to your organizer in Windows and hold Shift while right-tapping on a clear zone of the envelope and picking Open Command Prompt.


How to make a Discord bot
How to make a Discord bot

How to make a bot on discord Step 9: Use the Command Prompt to install your bot’s dependencies


Presently it's an ideal opportunity to utilize Node.js. In the Command Prompt, with your Discord bot envelope in the document way line, type "npm introduce discord.io winston – spare." This will naturally introduce records you have to for your Discord bot into the organizer straightforwardly.

Also, use the following command line prompt to install additional dependencies: npm install https://github.com/woor/discord.io/tarball/gateway_v6

Create a discord bot Step 10: Run the bot


That ought to be everything. To have a go at running your bot, type "hub bot.js" in the Command Prompt (ensure regardless you're explored to your Discord bot organizer). 

Presently head back to your Discord server and take a stab at testing your bot by composing "!introduction," or "!" pursued by whatever you made your brief message in your "bot.js" record. In the case of everything that went accurately, your bot ought to promptly restore the message you coded for it.

How to create a bot in discord Step 11: Figure out if your bot has been made by someone else


Discord has a major network of individuals making stuff for more noteworthy's benefit of the administration constantly, and that incorporates bots. There are entire databases of bots other individuals have made that play out an assortment of capacities, and frequently their makers make those bots accessible for anybody to download and utilize. Spare yourself some time and some coding by looking at a portion of the standard places where Discord bots are found, to check whether somebody has just done your work for you. 

Some convenient spots to scan for Discord bots are discordbots.org and bots.discord.pw, but on the other hand, you're probably going to have karma googling for what you need, too.


No comments:

Post a Comment

We, Will, Be Happy To Read You