Follow these steps and you will have a bot in no time!

Requirements

All you need is:

  • Discord Bot hosting
  • Text Editor
  • Basic knowledge of Javascript

If you don't already have a discord bot hosting you can use Primed Hosting.


After you get your server make a new file called index.js and in that we will have the following


const Discord = require('discord.js');
const client = new Discord.Client();


client.on('ready', () => {
  console.log('I am ready!');
});


// Log your bot in using the token from https://discord.com/developers/applications
client.login('your token here');


That now just runs your bot, to add commands here is what you need to add:


client.on('message', msg => { \\checks when someone types in chat
  if (msg.content === 'gn') { \\if the message is gn
    msg.reply('Good Night'); \\the bot replys with Good Night
  }
});

Image

Code Your Own Discord Bot - Basics (2021)