185 words
1 minute
Building Discord Bots - A Complete Guide

Building Discord Bots#

Discord bots are one of my favorite things to build. Here’s how I do it!

Why Discord Bots?#

  • Great for gaming communities
  • Automate repetitive tasks
  • Fun to build and share
  • Clients love them!

Python Approach (discord.py)#

Setup#

Terminal window
pip install discord.py

Basic Bot#

import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())
@bot.event
async def on_ready():
print(f'{bot.user} is online!')
@bot.command()
async def ping(ctx):
await ctx.send(f'Pong! {round(bot.latency * 1000)}ms')
@bot.command()
async def hello(ctx):
await ctx.send(f'Hey {ctx.author.mention}!')
bot.run('YOUR_TOKEN')

JavaScript Approach (discord.js)#

Setup#

Terminal window
npm init -y
npm install discord.js

Basic Bot#

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', message => {
if (message.content === '!ping') {
message.reply('Pong!');
}
});
client.login('YOUR_TOKEN');

Cool Features to Add#

Slash Commands#

client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});

Embeds#

embed = discord.Embed(
title="Welcome!",
description="Thanks for joining our server!",
color=discord.Color.blue()
)
embed.set_footer(text="Made by LUKKID")
await ctx.send(embed=embed)

Bot Ideas#

Bot TypeFeatures
ModerationKick, ban, mute, warnings
MusicPlay from YouTube, Spotify
GamesTrivia, mini-games
UtilityReminders, polls, tickets
EconomyCurrency, shop, gambling

Hosting Options#

  • Railway - Easy, free tier
  • Heroku - Classic choice
  • VPS - Full control
  • Raspberry Pi - Self-hosted fun!

Start simple, add features as you go!

Building Discord Bots - A Complete Guide
https://blog.lukkid.dev/posts/discord-bots-guide/
Author
LUKKID
Published at
2024-02-20
License
CC BY-NC-SA 4.0