Complete Guide About Adding Bots to a Discord Server

Complete guide about adding bots to a discord server.

Discord – the free chat service for gamers – is very popular and used by thousands of gamers around the world. The app is very easy to use, and managing servers on Discord is pretty straightforward as well. Although the app itself is very powerful, there are always ways to add more functionality.  Different people use Discord in their own ways. To customize your Discord server and add functionality, Discord users can add bots to their servers. So if you want to add bots to a Discord server, here’s what you can do:

Note: To add bots to a server, you must have the “Manage Server” permission on the server to which you are adding the bot.

Add bots to your Discord server

Adding bots to a Discord server is actually pretty straightforward as it should be. All you have to do is log into your Discord account in a browser and you are good to go. I’m assuming you already have the bots you want to add to your Discord server. If you are looking for Discord bots, you can visit the Carbonitex website or the unofficial Discord Bot website to find the best bots to add to your server. Once you have the bots you want to add to your server, follow these steps:

  1. Visit the Discord app website and sign in to your Discord account. Make sure you have “Manage Server” permission on the server you want to add the bot to.
  2. On the Carbonitex website, click the “Add bot to server” button. When adding a bot from the Discord Bots website, click the Invite button.
  3. You will be taken to an authorization screen. Here, click on the “Select a server” drop-down menu and select the server to which you want to add the bot.
  4. Simply click on the “Allow” button. When you have done this, the bot will be added to your server and you will be able to see it in your server sidebar.

These are all the steps on how to add a bot to your Discord server.

How to add bots to discord
How to add bots to discord

(Image)

Note: Many Discord bots are also hosted on GitHub. To install them, you can check out the GitHub projects wiki where you can find the bot installation guide. It is not possible to cover them in one article as the methods differ from bot to bot.

Easily add bots to a Discord server

With the passage of time, your server size will increase because of adding bots of your choice. This is not a question of single bot rather you can add multiple bots on your Discord server. You need to access the sites as I have told you and select bot of your interest. The app itself has many functions, which will make your way easy to grow.

Creation of the application

To interact with the API and create our bot, you will have to start by obtaining an API key. To do this, you have to go to the developer area and create a new application.

Once this application has been created, you will need to press the ” Create a Bot User ” button in order to make our bot exist as a Discord user. You will then have access to a ” Token ” which you will need for the future.

Must Read Article: How to Find a Solution if your Internet Access is Blocked

Allow the bot to join the server

In order for the bot to be able to interact with the server, it will have to be given the right permissions. To make things easier for you, you can use this permission generator which will allow you to obtain the authorization link that you will need to provide to administrators who wish to add your bot to their server.

The code!

Now that we have the Token and our bot is authorized to access the server, we will be able to connect it. We start by downloading discord.js

npm i –save discord.js

Then, we can connect our bot via the object Client.

const Discord = require(‘discord.js’)

const bot = new Discord.Client()

bot.on(‘ready’, function () {

  console.log(“Je suis connecté !”)

})

bot.login(‘TOKEN’)

This client object will be the central point of our bot and will allow us to listen to various events and react accordingly.

Ping / Pong

We will start by listening for incoming messages and detecting when a user writes the word ping

bot.on(‘message’, message => {

  if (message.content === ‘ping’) {

    message.reply(‘pong !’)

  }

})

The event message returns as a parameter an instance of Message which is an object of Discord.js which has several properties and methods that you can use to interact with the API.

welcome

To welcome your users you can use the event guildMemberAdd

bot.on(‘guildMemberAdd’, member => {

  member.createDM().then(channel => {

    return channel.send(‘Welcome to my server’ + member.display Name)}). Catch (console.error) // We could catch the error otherwise here (user may have MP disabled)

})

Channel Audio

It is also possible to connect our bot to a voice channel and transmit various audio streams. For example, when the user types the command!

bot.on(‘message’, message => {

if (message.content.startsWith (‘! play’)) {

     // We get the first audio channel from the server

     let voiceChannel = message.guild.channels

       .filter (function (channel) {return channel.type === ‘voice’})

       .first ()

     // We get the arguments of the command

     // we should use a regular expression to validate the youtube link

     let args = message.content.split (”)

     // We join the audio channel

     voiceChannel

       .join ()

       .then (function (connection) {

         // We start a stream from the youtube video

         let stream = YoutubeStream (args [1])

         stream.on (‘error’, function () {

           message.reply (“I failed to play this video :(“)

           connection.disconnect ()

         })

         // We send the stream to the audio channel

         // Here we should avoid overlays (send several videos at the same time)

         connection          .playStream(stream)

          .on(‘end’, function () {

            connection.disconnect()

          })

      })

  }

})

To infinity and beyond !

As you could see through these various examples, Discord.js offers classes to represent the different Discord concepts and allows to interact with the API in a very simplified way. So don’t hesitate to experiment.

LEAVE A REPLY

Please enter your comment!
Please enter your name here