Files
bot.py
README.md
requirements.txt
Code
3 396
bot.py
import discord
from discord import app_commands
from discord.ext import commands
import os
from dotenv import load_dotenv
from datetime import timedelta
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
load_dotenv()
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
EMBED_COLOR = discord.Color.blue()
@bot.event
async def on_ready():
logging.info(f'Bot is ready! Logged in as {bot.user}')
try:
synced = await bot.tree.sync()
logging.info(f'Synced {len(synced)} slash command(s)')
except Exception as e:
logging.error(f'Failed to sync commands: {e}')
@bot.tree.command(name="pesend", description="Send an embed message to a specified channel")
@app_commands.describe(
title="The title of the embed",
description="The description of the embed",
channel="The channel to send the embed to"
)
@app_commands.checks.has_permissions(manage_messages=True)
async def pesend(
interaction: discord.Interaction,
title: str,
description: str,
channel: discord.TextChannel
):
try:
embed = discord.Embed(
title=title,
description=description,
color=EMBED_COLOR
)
embed.set_footer(text=bot.user.name, icon_url=bot.user.avatar.url if bot.user.avatar else None)
await channel.send(embed=embed)
await interaction.response.send_message(
f"✅ Embed successfully sent to {channel.mention}",
ephemeral=True
)
logging.info(f'{interaction.user} sent an embed to #{channel.name} with title: {title}')
except discord.Forbidden:
await interaction.response.send_message(
"❌ I don't have permission to send messages in that channel.",
ephemeral=True
)
except Exception as e:
await interaction.response.send_message(
f"❌ An error occurred: {str(e)}",
ephemeral=True
)
logging.error(f'Error in pesend command: {e}')
@pesend.error
async def pesend_error(interaction: discord.Interaction, error):
if isinstance(error, app_commands.errors.MissingPermissions):
await interaction.response.send_message(
"❌ You need the 'Manage Messages' permission to use this command.",
ephemeral=True
)
@bot.tree.command(name="mute", description="Temporarily mute (timeout) a member")
@app_commands.describe(
user="The member to mute",
duration="Duration in minutes",
reason="Reason for the mute (optional)"
)
@app_commands.checks.has_permissions(moderate_members=True)
async def mute(
interaction: discord.Interaction,
user: discord.Member,
duration: int,
reason: str = "No reason provided"
):
try:
if user.id == interaction.user.id:
await interaction.response.send_message(
"❌ You cannot mute yourself.",
ephemeral=True
)
return
if user.guild_permissions.administrator:
await interaction.response.send_message(
"❌ You cannot mute an administrator.",
ephemeral=True
)
return
if duration <= 0:
await interaction.response.send_message(
"❌ Duration must be a positive number.",
ephemeral=True
)
return
if duration > 40320:
await interaction.response.send_message(
"❌ Duration cannot exceed 40320 minutes (28 days).",
ephemeral=True
)
return
timeout_duration = timedelta(minutes=duration)
await user.timeout(timeout_duration, reason=reason)
await interaction.response.send_message(
f"✅ {user.mention} has been muted for {duration} minute(s).\nReason: {reason}",
ephemeral=True
)
logging.info(f'{interaction.user} muted {user} for {duration} minutes. Reason: {reason}')
try:
await user.send(f"You have been muted in **{interaction.guild.name}** for {duration} minute(s).\nReason: {reason}")
except discord.Forbidden:
pass
except discord.Forbidden:
await interaction.response.send_message(
"❌ I don't have permission to timeout this member.",
ephemeral=True
)
except Exception as e:
await interaction.response.send_message(
f"❌ An error occurred: {str(e)}",
ephemeral=True
)
logging.error(f'Error in mute command: {e}')
@mute.error
async def mute_error(interaction: discord.Interaction, error):
if isinstance(error, app_commands.errors.MissingPermissions):
await interaction.response.send_message(
"❌ You need the 'Moderate Members' permission to use this command.",
ephemeral=True
)
@bot.tree.command(name="unmute", description="Remove timeout from a member")
@app_commands.describe(user="The member to unmute")
@app_commands.checks.has_permissions(moderate_members=True)
async def unmute(interaction: discord.Interaction, user: discord.Member):
try:
if user.timed_out_until is None:
await interaction.response.send_message(
f"❌ {user.mention} is not currently muted.",
ephemeral=True
)
return
await user.timeout(None)
await interaction.response.send_message(
f"✅ {user.mention} has been unmuted.",
ephemeral=True
)
logging.info(f'{interaction.user} unmuted {user}')
try:
await user.send(f"You have been unmuted in **{interaction.guild.name}**.")
except discord.Forbidden:
pass
except discord.Forbidden:
await interaction.response.send_message(
"❌ I don't have permission to remove timeout from this member.",
ephemeral=True
)
except Exception as e:
await interaction.response.send_message(
f"❌ An error occurred: {str(e)}",
ephemeral=True
)
logging.error(f'Error in unmute command: {e}')
@unmute.error
async def unmute_error(interaction: discord.Interaction, error):
if isinstance(error, app_commands.errors.MissingPermissions):
await interaction.response.send_message(
"❌ You need the 'Moderate Members' permission to use this command.",
ephemeral=True