How will tough to make a discord bot.

How will tough to make a discord bot.

It seems like it is tough to make a Discord bot. But it is so easy to build it. So now we are going to create this.

Requirement

  1. Discord Account.

  2. Node js in your machine.

  3. Code Editor.

  4. Excitement

for the first step go to discord.com and create a free Account.

SETUP 1

After creating a discord account you will have to add a bot to your account and for this to go to the discord developer portal.

Click on ‘New Application’ and then it will ask you to name your application. You can give anything.

Now After giving the name got to ‘Add Bot'

Note - Do not give your token to anyone the token will be used later to make node.js and control the bot.

Now you will have to invite your bot to the server.

but first, you should have a server. so create a free server on Discord.

then you will have to invite your bot to the server.

invite ??

Go to 'OAuth2' and then click on bot in the scopes.

A link will be generated automatically. Copy it and paste it into the browser.

When you go into the link it will ask you to choose one of the servers from the dropdown menu that you are allowed to invite the bot to. so select the one that you created. and this bot will join your server.

It's Time to Ptogram our Bot😎

In Terminal

npm init -y

npm install discord.js

and create an index.js file where we will going to code your bot.

// index js file  
const { Client, GatewayIntentBits, makeError } = require ('discord.js');
const client = new Client({ intents: [

    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent

]});
client.on('messageCreate',(message)=>{
      // reply of message
      if(message.author.bot){
        return;
        }
     else{
         message.reply( {
         content: "Hii Form Saurabh's Bot"
         }) 
         }
client.login("put your token that was in the discord developer portal.")

if you want to understand this thing then go to DEVELOPER PORTAL

or check out the official documentation on discord.js

In simple these are the gateways and classes(objects) which help to send and receive messages from discord servers.

This discord bot works only locally you can host it on any hosting platform and it will work. Globally

Thank you for reading my content. Be sure to follow and comment on what you want me to write about next 🤓

Did you find this article valuable?

Support Saurabh verma by becoming a sponsor. Any amount is appreciated!