Introduction
Welcome to Botland.lol, your complete Discord API manual. Page 1 introduces the basics of bots, REST API, events, commands, embeds, webhooks, files, and voice features.
Getting Started
Create a bot in the Developer Portal. Install the library:
pip install discord.py
Basic Bot Code
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
print("Bot online")
@bot.command()
async def hello(ctx):
await ctx.send("Hello!")
bot.run("TOKEN")
Events
@bot.event
async def on_member_join(member):
channel = discord.utils.get(member.guild.text_channels, name="general")
await channel.send(f"Welcome {member.mention}")
Commands
@bot.command()
async def add(ctx, a: int, b: int):
await ctx.send(str(a+b))
Embeds
@bot.command()
async def info(ctx):
embed = discord.Embed(title="Info", description="Example", color=0x00ff00)
embed.add_field(name="Made By", value="MisterCoolGuy123")
await ctx.send(embed=embed)
Files & Attachments
@bot.command()
async def sendfile(ctx):
await ctx.send(file=discord.File("pic.png"))
Webhooks
import requests
url = "WEBHOOK_URL"
data = {"content": "Hello from Webhook!"}
requests.post(url, json=data)
Voice
@bot.command()
async def join(ctx):
if ctx.author.voice:
await ctx.author.voice.channel.connect()
@bot.command()
async def leave(ctx):
if ctx.voice_client:
await ctx.voice_client.disconnect()
Rate Limits
Discord restricts how often you can send requests. The REST API returns headers like X-RateLimit-Remaining
. Exceeding limits gives HTTP 429.
OAuth2 Basics
OAuth2 lets bots join servers. Example invite link format:
https://discord.com/oauth2/authorize?client_id=APP_ID&scope=bot&permissions=8