Skip to content

DeddCode31251/Discord-Bot-using-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Discord-Bot-using-javascript

discord bot using javascript made by deadcode Discord Bot with JavaScript

This README explains how to create a simple Discord bot using JavaScript and the discord.js library.

๐Ÿ“ฆ Requirements

Node.js (v18 or higher recommended)

npm (comes with Node.js)

A Discord account

Access to the Discord Developer Portal

โš™๏ธ Step 1: Create a New Application

Go to the Discord Developer Portal.

Click New Application and give it a name.

Navigate to the Bot tab and click Add Bot.

Copy the Bot Token (youโ€™ll need this later).

โš™๏ธ Step 2: Set Up Your Project

Create a new folder for your bot project.

Open a terminal in that folder.

Initialize npm:

npm init -y

Install required libraries:

npm install discord.js dotenv

โš™๏ธ Step 3: Create Your Bot File

Create a file named index.js (or main.js) and add the following code:

const { Client, GatewayIntentBits } = require('discord.js'); require('dotenv').config();

const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent ] });

client.once('clientReady', () => { console.log(โœ… Logged in as ${client.user.tag}); });

const prefix = "/";

client.on('messageCreate', message => { if (message.author.bot) return;

if (message.content === ${prefix}hello) { message.reply('๐Ÿ‘‹ Hello there!'); }

if (message.content === ${prefix}ping) { message.reply('๐Ÿ“ Pong!'); }

if (message.content === ${prefix}roll) { const number = Math.floor(Math.random() * 100) + 1; message.reply(๐ŸŽฒ You rolled a ${number}!); } });

client.login(process.env.BOT_TOKEN);

โš™๏ธ Step 4: Add Environment Variables

Create a .env file in the root of your project:

BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN

Replace YOUR_DISCORD_BOT_TOKEN with the token you copied from the Developer Portal.

โš™๏ธ Step 5: Invite Your Bot to a Server

In the Developer Portal, go to OAuth2 โ†’ URL Generator.

Select bot and applications.commands scopes.

Choose permissions (e.g., Send Messages).

Copy the generated URL and open it in your browser.

Invite the bot to your server.

๐Ÿš€ Step 6: Run Your Bot

In your terminal:

node index.js

You should see:

โœ… Logged in as YourBotName#1234

๐Ÿ“š Libraries Used

discord.js โ†’ Core library to interact with Discord API.

dotenv โ†’ Loads environment variables from .env file for secure token management.

About

discord bot using javascript made by deadcode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors