Skip to content

CovenDeity/Discord-Bot-JavaScript

Repository files navigation

Discord-Bot-JavaScript

Basic Discord bot written in JavaScript

  • Make Discord account if you don't have one already.

Discord - Register a new account

Discord - Register a new account

  • Goto to the Discord Developer Portal and click New Application

Discord - Developer Portal

Discord - Developer Portal

  • NAME your bot, Check the box and click Create

Create And Application

  • Click Bot on the left
  1. PRESENCE INTENT (toggle on)
  2. SERVERS MEMBERS INTENT (toggle on)
  3. MESSAGE CONTENT INTENT (toggle on)
  4. Administrator (check box)
  5. Save Changes
  6. Reset Token

Choose Bot Application

  • Click Yes, do it!

Yes, do it!

  • in a Terminal window
mkdir MyJavaScriptBot
cd MyJavaScriptBot/
npm init --yes
touch config.js
touch index.js
nano config.json
  • In the Discord Developer Portal click Copy to copy your bot's private TOKEN (always keep this private)

Copy your bot private TOKEN

  • back in the terminal (nano still open)
{
    "token": "<paste your copied token here>",
}
  • In the Discord Developer Portal
  1. click OAuth2
  2. click URL Generator
  3. click bot
  4. check the Administrator check box
  5. click Copy

OAuto2 steops

  • back in the terminal (nano still open)
{
    "token": "<paste your copied token here>",
    "inviteURL": "<paste the copied URL here>",
}
  • open a new TAB in your Web-Browser and paste the copied URL in the Address bar of the new TAB (don't press ENTER)
  • click back to the Discord Developer Portal TAB
  • In the Discord Developer Portal (see image below showing steps in Developer Portal)
  1. click General Information
  2. click Copy button under APPLICATION ID
  • back in the terminal (nano still open)
{
    "token": "<paste your copied token here>",
    "inviteURL": "<paste the copied URL here>",
    "applicationID": "<paste copied APPICATION ID here>"
}
  • In the Discord Developer Portal
  1. click Copy button under PUBLIC_KEY
  • back in the terminal (nano still open)
{
    "token": "<paste your copied token here>",
    "inviteURL": "<paste the copied URL here>",
    "applicationID": "<paste copied APPICATION ID here>",
    "publicKey": "<paste your copied PUBLIC_KEY here>"
}
  1. CTRL+O -> ENTER -> CTRL+X

General Information

  • Create a Discord Server (also known as a Guild)

Discord - Create a server

  • click the new TAB you opened earlier in your Web-Browser and click enter on the Address you pasted in the Address bar

Choose your server from the Drop-Down box then click Continue

Add the Bot to your Server

Click Authorize

Authorize the bot

  • The bot (which still needs the code written for) should now be OFFLINE on your server, next we will write the code to make the bot perform

Bot OFFLINE on server

  • back in the terminal
npm install discord.js
nano index.js
const Discord = require("discord.js");
const { token } = require('./config.json');
const allIntents = Discord.Intents;
const { Client, Events } = require('discord.js');
const client = new Client({ intents: 3276799 });

client.once(Events.ClientReady, c => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.on(Events.MessageCreate, async (interaction) => {
    console.log(interaction.content);
    if (interaction.content.toLowerCase() === 'hello') {
        await interaction.reply({ content: `Hello, ${interaction.author.username}. Have a wonderful day!`, ephemeral: false });
    }
});

client.login(token);
> CTRL+O -> ENTER -> CTRL+X
node index.js

Congratulations, on making your first Discord bot in JavaScript

Notes

About

Discord-Bot-JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published