Discord.js-Bot-Template
This is a very simple template for making bots using Discord.js/Node.js
Tutorial:
To begin, Install Node.js here.
After Node.Js is succesfully installed run the following command in the folder where the files for your discord bot will be and fill in the information:
npm init
Create an app in the Discord Developer Portal and on the left go to Bot > Build-A-Bot
to set up the bot
In the main.js
type the following:
const Discord = require('discord.js'); const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] }); const token = ''; const PREFIX = ''; bot.on('ready', () => { console.log("I am online!") }) bot.on("message", msg => { if (msg.content === PREFIX + "ping") { msg.reply("pong"); } }) bot.login(token)
Edit the const token = ''
to your bot's token you've been given. DO NOT SHARE THIS TOKEN WITH ANYONE!
Optional Edit the const PREFIX = ''
if you want to use a prefix for messages, For example =ping would be const PREFIX = '='
To create an invite link for your bot. Go to the Discord Developer Portal and on the left go to OAuth2 > URL Generator
and choose the option Bot
under Scopes
. You can edit the bots permissions how you like.
To make the bot temporarily online, type the following in the command prompt in the folder with the files:
node .
You should get a response like "I am online!". in the Command Prompt.
To test your bot, Invite the bot to a server and type ping
in the chat. When you get a reply from the bot with pong
it means that the bot is working! You can now edit the code and add new features to it.
To learn more about discord.js Click the link to go to the discord.js documentation.
Help/Support
I'm actually not intending to help everyone with any problems with the tutorial. if there's a bug i'll recommend searching for discord.js related help. You can always go to the discord.js discord server to ask help. (link is here down below)