Aug 5, 2025 02:31 PM
(This post was last modified: Aug 5, 2025 02:37 PM by Vectura.)
🤖 [Discord.js Bot Guide] - Step-by-Step Tutorial w/ Moderation Commands
Perfect for beginners. Works in private & public servers!
🎒 REQUIREMENTS
• Node.js → https://nodejs.org
• Code Editor (e.g. Visual Studio Code → https://code.visualstudio.com)
• Discord account → https://discord.com
🚀 STEP 1–4: CREATE BOT IN DISCORD DEVELOPER PORTAL
1. Go to: https://discord.com/developers/applications
2. Click "New Application" → Give it a name → Click "Create"
3. On the left: Go to "Bot" → Click "Add Bot" → Confirm
4. Under Privileged Gateway Intents: Enable:
- SERVER MEMBERS
- MESSAGE CONTENT
🔐 STEP 5–6: SETUP TOKENS & PERMISSIONS
5. Copy your Bot Token (you’ll need it later). Also copy Client ID.
6. Generate bot invite link (replace YOUR_CLIENT_ID):
Bot Invite Link
💻 STEP 7–10: LOCAL SETUP
7. Create folder "mybot" and open terminal inside it
8. Run:
npm init -y
9. Then run:
npm install discord.js@14 dotenv
10. Create files:
• index.js
• .env → Add:
BOT_TOKEN=your_token_here
📜 STEP 11–13: BASIC BOT CODE
[index.js]
Code
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
client.once('ready', () => {
console.log(`✅ Logged in as ${client.user.tag}`);
});
client.login(process.env.BOT_TOKEN);💬 STEP 14–16: BASIC COMMANDS
Add inside your file:
Code
client.on('messageCreate', msg => {
if (msg.author.bot) return;
if (msg.content === '!ping') {
msg.reply('🏓 Pong!');
}
if (msg.content === '!hello') {
msg.reply(`Hello, ${msg.author.username}!`);
}
});🛡️ STEP 17–21: MODERATION COMMANDS
Add more commands below:
Code
// Kick
if (msg.content.startsWith('!kick')) {
const member = msg.mentions.members.first();
if (!member) return msg.reply('Mention someone!');
if (!msg.member.permissions.has('KickMembers')) return msg.reply('You need Kick permissions.');
member.kick().then(() => msg.reply(`${member.user.tag} has been kicked.`));
}
// Ban
if (msg.content.startsWith('!ban')) {
const member = msg.mentions.members.first();
if (!member) return msg.reply('Mention someone!');
if (!msg.member.permissions.has('BanMembers')) return msg.reply('You need Ban permissions.');
member.ban().then(() => msg.reply(`${member.user.tag} has been banned.`));
}
// Mute
if (msg.content.startsWith('!mute')) {
const role = msg.guild.roles.cache.find(r => r.name === "Muted");
const member = msg.mentions.members.first();
if (!role) return msg.reply('Create a role named "Muted" first.');
if (!member) return msg.reply('Mention someone!');
member.roles.add(role);
msg.reply(`${member.user.tag} has been muted.`);
}🚦 STEP 22: START YOUR BOT LOCALLY
After you’ve written your code, it’s time to run your bot for the first time!
In your terminal, inside the “mybot” folder, run:
Code
node index.jsIf everything is set up correctly, you’ll see this in your terminal:
Code
✅ Logged in as YourBotName#1234💡 Keep your terminal open to keep your bot online.
To stop the bot, press CTRL + C.
🔧 STEP 23–26: EXTRA TIPS
23. Create a “Muted” role in your server with no send permissions in channels
24. You can expand with commands like !unmute, !userinfo, !serverinfo, etc.
25. Use .env to hide secrets — NEVER commit it to GitHub!
26. Host your bot on Repl.it, Glitch, Heroku or use VPS for 24/7 uptime
✅ YOUR BOT IS READY!
Join your server, type !ping or !kick @user and you’re good to go.
Feel free to share your bot invite with friends or keep it private.
In the next tutorial I'll go into more detail about slash commands, for example, or leave your suggestions in the comments, and who knows, I might work them out for you!


