how to make discord js bot code example

Example 1: discord.js bot

//first you must install dicord.js by running the command: npm install discord.js
//once u do that copy and paste this into your main file
const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () =>{
	client.user.setStatus('your status')
	console.log('Connected!')
})
//rest of your code

//always remember to never share your token with anyone
client.login('your-token-here')

Example 2: discord.js start code

const Discord = require('discord.js') //this says that its using discord.js and classifing it as a bot
const bot = new Discord.Client();

const token = 'put your bots token here!';
//link to the dev portal to make your own discord bot here: https://discord.com/developers/applications

Example 3: Discord.js Basics

const Discord = require("discord.js")
const client = new Discord.Client()
client.on("ready", ()=>{
console.log(`Logged in as ${client.user.tag}`)
})
client.on("message", async function (message) {
  if(message.content === "!test") {
	message.reply("Hello World!")
  }
})

Example 4: how to get a bot online on discord

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

const TOKEN = "put ur token";

bot.login(TOKEN);

Tags: