How to Make Your Own Discord Bot

How to Make Your Own Discord Bot – Discord has an excellent API for writing custom bots, and a very active community bot. Today we take a look at how to get started making your own.

Need a little knowledge of programming code a bot, so it’s not for everyone, but fortunately there are some modules for the common languages ​​that make it very easy to do. We are among the most popular, discord.js.

Steps On Making Your Own Discord Bot

First step

Go to discord the bot portal and create a new application.

step 1 - make your own discord bot

You want to make a note of the client ID and secret (this should be kept secret, of course). However, this is not the bot, just the “application”. Need the bot under the “bot” tab.

step 2

Record this token as well, and keep it secret. Not, under any circumstances, commit this key to Github. Your bot be hacked almost immediately.

Install Node.js and get coding

To execute javascript code outside of a webpage, you must use the nodes. Download it, install it, and make sure it works in a terminal (or the command prompt, as that should all be on Windows systems). The standard command “Node.”

We also recommend installing the nodemon tool. It is a command line app that monitors your bot code and restarts automatically for changes. You can install it by running the following command:

npm ig nodemon

You need a text editor. You could only use the editor, but we recommend the Atom or VSC.

Here is our “hello world”:

hello world

const discard = require (‘discord.js’);
const client = new Discord.Client ();

client.on (‘ready’ -, () => {
console.log (`Logged in as $ {client.user.tag}!`);
});

client.on (‘message’, msg => {
if (msg.content = = = “ping”) {
msg.response (‘pong’);
}
});

client.login ( ‘token’);

This code comes from the discord.js example. Let us break it.

  • The first two lines are to configure the client. Line one imports the module into an object called “discord”, and line initializes the client object.
  • The client.on (‘ready’) block is thrown when the bot starts. Here it is just configured to report your name on the terminal.
  • The client.on (‘message’) block is fired every time a new message is posted from each channel. Of course, you will need to check the content of the message, and that’s what the block does. If the message just says “ping,” then respond with “Pong!”
  • The last line logs in with the token from the bot portal. Obviously the token in the picture here is fake. Do not always post your character on the internet.

Copy this code, paste in your token at the bottom, and save it as index.js in a separate folder.

How to get the bot up and running

how to make a discord bot

Head over to your terminal and run the following command:

nodemon -check index.js

This launches the script, and also fires up the Chrome debugger, which you can access by entering chrome: // inspect / into Chrome’s Omnibar and then opening “dedicated devtools for the knot.”

Well, it should just say “Logged in as <bot-name>”, but here I have a line that gets all the message objects to the console:

discord bot creation

Continue Reading At Toptenbiz Here : How To Make a Doscord Bot – Toptenbiz