قالب وردپرس درنا توس
Home / Tips and Tricks / How to Make a Discord Bot

How to Make a Discord Bot



Update 8/21/2018: Some changes have been made to the code, with some additional instructions added to fix two common bugs that some readers found during the tutorial.

The rise of Discord, a gamers favorite chat and voice program, has made it quite common for Internet residents to find themselves hanging around "discord servers" based on a variety of topics. In fact, one of the best things about Discord is that you can easily create your own free server, decorate it with channels, and invite it to whoever you want to join.

(If you are not, read our full review of the service and how it works.)

One of the coolest features of Discord is the ability to create automated user bots that can perform various functions. These bots are coded in JavaScript and can be quite complex. For example, they play music for users on a server, greet new users upon arrival, and much more.

Creating your own Discord Bot does not require much effort, even if you're new to coding and JavaScript in general. Here's everything you need to know to make a (super, super easy) Discord bot.

Step 1
: Download Node.js and set up a Discord account if you do not have

Node.js is javascript runtime that is free and open source and you will need it to your bot, uh, actually working. Download it at nodejs.org and install it before you start with anything else.

Of course you also need a Discord account and your own server to test your bot. If you have not already created one, go to Discordapp.com and create one. If you have one, log in to your account and open the server where your bot will live.

You also need a text editor program like Notepad ++ on Windows that you can use to program.

Step 2: Create Your Bot

  How to Make a Diskord Bot My Apps

Now you need to create an "application" on Discord for your bot to work. This requires a bit of doing, but it's not too complex. The goal here is to get an "authorization token" for the bot so that Discord recognizes your code and adds it to the bot on its servers.

First go to discordapp.com/developers/applications/me. Your account should be signed in to get you directly to the application list of your account. Click "New Application" to get started. Give the bot a name and then click on the "Save Changes" button.

Now click on "Bot" in the right menu. In the new menu, click on "Add Bot" under the Build-a-bot option. If you have only one application – the one we just created – it should appear automatically. Otherwise, select it.

Step 3: Receive Your Bots Authorization Token

  How to Make a Bot Box for Discord

Click in the "App Bot User" box for the words "Token: Click to View." You on this link and you will receive a text string. This is the authorization token of your bot, which you can use to send code. Do not Tell Anyone – This token allows anyone who has code to create the bot, meaning whoever has it can control your bot. If you believe that the token has been compromised, you can easily create a new link with the link just below the token, which reads, "Generate a new token."

You only need this token in one

Step 4: Send your bot to your server

  How to connect a discord bot with dissonances

Now scroll to the box labeled "App Details" and find your "Client ID", a long number. Copy the number and add it to this URL instead of the word CLIENTID.

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

The final URL should look like this: but with your customer number in it instead of this counterfeit:
https: // discordapp. com / oauth2 / authorize? & client_id = 000000000000000001 & scope = bot & permissions = 8

Copy the URL with your customer number into your browser. This brings you to a website where you can tell Diskord where to send your bot. You'll know that it works when you open Discord in an app or in your browser and navigate to your server. The channel says that a bot has joined the room, and you can see it on the right side under the list of online members.

Step 5: Create a "Bot" Folder on Your Computer

  a Discord Bot Folder

Meanwhile, you can take a moment to move a folder to an easily accessible location on your computer on which you can save all your bot files. Just name it, like "DiscordBot" or "MyBot," so you know exactly what it is.

Step 6: Open Your Text Editor and Make Your Bot Files

  How to Create a Discord Bot Code

You will create three files for your bot from your text editor. Insert in the first code:

{
"token": "Your bot token"
}

Replace "your bot token" with the token that you previously generated on your bot's application page have. Make sure the token is inside the quotation marks. Then save the file to the Discord Bot folder you created on your desktop with the file name "auth.json". Remember to not save it as a .txt file – it will not work if it's .txt instead of .json. 19659003] Make a new file and enter the following code:

{
"name": "greeeter-bot",
"version": "1.0.0",
"description": " My First Discordian Bot ",
" main ":" bot.js ",
" Author ":" Your Name ",
" Dependencies ": {}
}

Replace the author name Your name, if you like; You can also change the "description" to something other than "My First Discordion Bot" if you are doing something more in line with what you want to do, which will be useful to remember what your bot is supposed to do.

Save this file as "package.json" in your Discord Bot folder.

Step 7: Define Your Bots Code

  How to Make a Discord Bot Bots

There's still one text file to make, and that's the one important thing that controls the behavior of your bot. You'll need to be familiar with JavaScript to really have full control over your bot and to know what you're doing, but if you're new to coding and just want to do something, you can copy that code and paste it into the file ( 19659003) (Thanks to media user Renemari Padillo, whose bot tutorial helped us create this. Read his troubleshooting tutorial and other advice.)


  var Discord = require (& # 39; discord.io & # 39);
var logger = require (& # 39; winston & # 39;);
var auth = require (& 39; / auth.json & # 39;);
// configure logger settings
logger.remove (logger.transports.Console);
logger.add (new logger.transports.Console, {
colorize: true
});
logger.level = & # 39; debug & # 39 ;;
// Initialize Discord Bot
var bot = new Discord.Client ({
Token: auth.token,
Autorun: True
});
Bot.on (& # 39; ready & # 39 ;, function (evt) {
logger.info (& # 39; connected & # 39;);
logger.info (& # 39; logged in as: & # 39;);
logger.info (bot.username + # - (& # 39; + bot.id + & # 39;) & # 39;);
});
bot.on (& # 39; message & # 39 ;, function (user, userid, channelid, message, evt) {
// Our bot needs to know if it is executing a command
// We search for messages starting with `!`
if (message string (0, 1) == & # 39;! & # 39;) {
var args = message string (1). split (& # 39; & # 39;);
var cmd = args [0];

args = args.splice (1);
change (cmd) {
//! ping
Case & # 39; ping & # 39 ;:
bot.sendMessage ({
to: channel ID,
Message: "Pong!"
});
break;
// Just add any case commands if you want ..
}
}
});

This code sets up a discord bot that responds to certain messages: especially anything that has a "!" – character begins. In particular, we program the bot to respond to the "! Intro" command. So, if someone writes to the server while the bot is in it, the bot responds with a programmed message. In our code, we defined the message as "Greetings! Welcome to the server!" You can change both the prompt and the response message by redefining it in the above code. Be sure to maintain the single quotes around the messages.

Save this last text file as "bot.js" in your discord bot folder.

Step 8: Open the "Command Prompt" of your computer and navigate to your Discord Bot folder

  How to Create a Discord Bot Prompt

On a Windows PC, you can easily get to the command prompt, by clicking on the Windows icon and typing "Prompt" in the box. Once open, enter "cd" followed by the file path to your folder. On my computer, the command looks like this: cdUsersPhils DesktopDesktopDiscordBot. This should change the prompt line to include the file path to your folder.

Alternatively, you can navigate to your folder in Windows and hold down the Shift key while right-clicking an empty area of ​​the folder and choosing Open Command Prompt. "

Step 9: Use the command prompt to install the dependencies of your bot

  How to create a Diskordierungsbot command prompt node Bot js

Now it's time to use Node.js Enter in the command prompt with your discord bot folder in the file path "npm install discord.io winston -save". This will automatically install the files you need for your discord bot directly into the folder.

Also use the following command prompt prompts you to install more dependencies: npm install https://github.com/wooor/discord.io/tarball/gateway_v6

This should provide you with all the needed files.

Step 10: Run the bot [19659052] How to Make a Discord Bot Test “/>

That should be all.To try to run your bot, type "node bot.js" at the prompt (make sure you're still yours Navigate discord bot folder).

Now go back to your Discord server and try to test your bot by typing "! Intro," or "!" Followed by what you typed in bot.js. If everything is done correctly, your bot should immediately return the message you have coded for it.

Congrats! You have just made a discord bot!

Step 11: Find out if your bot was made by someone else

Discord has a large community of people who are constantly doing things for greater service, and that includes a bot. There are whole databases of bots made by other people who perform a variety of functions, and their creators often provide these bots for everyone to download and use. Save some time and coding by checking some of the usual places where discord bots are found to see if anyone has already done their job for you.

Some useful places for Diskord bots are Discordbots.org and Bots .discord.pw, but you may also be lucky enough to googling for what you need.






Source link