Discord has an excellent API for writing custom robots, and a very active bot community. Today, we will see how to start creating yours.
Discord bot users (or just bots) have nearly unlimited applications. For example, let’s say you’re managing a new Discord guild and a user joins for the very first time. Kensington expert mouse software. Excited, you may personally reach out to that user and welcome them to your community. You might also tell them about your channels or ask them to introduce themselves. Create your own discord bot in 5 minutes with no coding required. Use our discord bot maker to create a bot for moderation, music, twitch.tv, fortnite and more. Build a Free Discord bot with no coding required Make your own discord bot for free in 5 minutes with no coding required. Choose from over 300 commands to enable Moderation, Utilities, Economy and more.
You will need a little programming knowledge to code a bot, so it's not for everyone, but fortunately there are modules for popular languages that make it easy. We will use the most popular, discord.js.
RELATED:How to create, configure and manage your Discord server
To start
See you on Discord's bot portaland create a new application.
You want to note the client ID and the secret (which you must keep secret of course). However, it is not the bot, but the application. You must add the bot under the Bot tab.
Discord Bot Maker No Code
Also note this token and keep it secret. Do not put this key in Github. Your bot will be hacked almost immediately.
Install Node.js and get the coding
To execute Javascript code outside of a web page, you need to Node. Download it, install it and make sure it works in a terminal (or prompt, because all of this should work on Windows systems). The default command is 'node'.
We also recommend installing the nodemon tool. It is a command-line application that monitors your bot's code and restarts automatically when making changes. You can install it by running the following command:
npm i -g nodemon
You will need a text editor. You can just use the notebook, but we recommend either Atom or VSC.
Here is our 'Hello World':
const Discord = require (& # 39; discord.js & # 39;);
client const = new Discord.Client ();
client.on ('ready', () => {
console.log (`Connected as $ {client.user.tag}!`);
})
client.on (& # 39; message, msg => {
if (msg.content & # 39; ping & # 39;) {
msg.reply (& # 39; pong & # 39;)
}
})
client.login (& # 39; token & # 39;);
This code is taken from discord.js Example. Let's break it.
The first two lines are used to configure the client. The first line imports the module into an object called 'Discord', and the second line initializes the client object.
The client.on ('ready') block is triggered when the bot starts. Here he is just configured to register his name on the terminal.
The client.on (& # 39;) block is triggered each time a new message is posted on a channel. Of course, you have to check the contents of the message, and that's what the if block does. If the message simply says 'ping', it will respond with 'Pong!'
The last line connects with the bot portal token. Obviously, the token in the screenshot is wrong. Never post your token on the Internet.
Copy this code, paste your token at the bottom and save it as index.js in a dedicated folder.
Discord Bot Maker Website
How to run the bot
Go to your device and run the following command:
nodemon –inspect index.js
This starts the script and also triggers the Chrome debugger, which you can access by typing chrome: // inspect / in Chrome Omnibar, and then opening 'dedicated devtools for Node'.
Now, just say 'Connected as But here I've added a line that will record all the message objects received on the console:
Best memory clean app. So, what constitutes this message object? Adobe lightroom 5. Many things, in fact:
Specifically, you have author and channel information that you can access with msg.author and msg.channel. I recommend this method of logging objects on Chrome Node devtools, and I'm just trying to see what works. You can find something interesting. Here, for example, the bot records its responses on the console, so the bot's responses trigger client.on ('message'). So, I did a spambot:
Note: Be careful with this because you do not really want to deal with recursion.
How to add the bot to your server
This part is harder than it should be. You must take this URL:
https://discordapp.com/oauth2/authorize?client_id=CLIENTID&scope=bot
And replace CLIENTID by the client ID of your bot, available in the General Information tab of the application page. Once done, you can give the link to your friends so that they also add it to their servers.
Okay, so what can I do?
Beyond the basic configuration, everything else depends entirely on you. But it would not really be a tutorial if we stopped at Hello World, so let's go over some of the Documentationso you have a better idea of what is possible. I suggest you read as much as you can, as this is very well documented.
I recommend adding console.log (client) at the beginning of your code and look at the client object in the console:
From here you can learn a lot. As you can add a bot to multiple servers at once, the servers are part of the Guilds map object. In this object are the individual Guilds (which is the name of the API for 'server') and these guild objects have channel lists containing all information and message lists. The API is very deep and may take some time to learn, but at least it is easy to set up and learn.