Files
bot.py
requirements.txt
Code
2 53
bot.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
OWNER_ID = int(os.getenv("OWNER_ID"))
def is_owner():
async def predicate(ctx):
return ctx.author.id == OWNER_ID
return commands.check(predicate)
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} ({bot.user.id})")
@bot.command()
@is_owner()
async def ban(ctx, member: discord.Member, *, reason="No reason provided"):
if member == ctx.author:
await ctx.send("You cannot ban yourself.")
return
if member.top_role >= ctx.guild.me.top_role:
await ctx.send(f"I don't have permission to ban {member}.")
return
await member.ban(reason=reason)
await ctx.send(f"✅ Banned **{member}** — Reason: {reason}")
@ban.error
async def ban_error(ctx, error):
if isinstance(error, commands.CheckFailure):
await ctx.send("❌ Only the bot owner can use this command.")
elif isinstance(error, commands.MemberNotFound):
await ctx.send("❌ Member not found.")
else:
await ctx.send(f"❌ Error: {error}")
bot.run(os.getenv("DISCORD_TOKEN"))