Files
bot.py
requirements.txt
Code
2 111
bot.py
import discord
from discord import app_commands
import os
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
class Bot(discord.Client):
def __init__(self):
super().__init__(intents=intents)
self.tree = app_commands.CommandTree(self)
async def setup_hook(self):
await self.tree.sync()
bot = Bot()
ROLE_ID = 1516099861169176576
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
@bot.tree.command(name="accept", description="Accept a forum post owner and assign them a role.")
@app_commands.checks.has_permissions(manage_roles=True)
async def accept(interaction: discord.Interaction):
channel = interaction.channel
if not isinstance(channel, discord.Thread) or not isinstance(channel.parent, discord.ForumChannel):
await interaction.response.send_message("This command can only be used inside a forum post.", ephemeral=True)
return
owner = channel.guild.get_member(channel.owner_id)
if owner is None:
try:
owner = await channel.guild.fetch_member(channel.owner_id)
except discord.NotFound:
await interaction.response.send_message("Could not find the forum post owner.", ephemeral=True)
return
role = channel.guild.get_role(ROLE_ID)
if role is None:
await interaction.response.send_message("The configured role could not be found.", ephemeral=True)
return
try:
await owner.add_roles(role)
except discord.Forbidden:
await interaction.response.send_message("I do not have permission to assign that role. Make sure my role is above it.", ephemeral=True)
return
await interaction.response.send_message(f"Successfully accepted {owner.mention}")
@accept.error
async def accept_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingPermissions):
await interaction.response.send_message("You do not have permission to use this command.", ephemeral=True)
@bot.tree.command(name="deny", description="Deny a forum post owner from the SMP.")
@app_commands.checks.has_permissions(manage_roles=True)
async def deny(interaction: discord.Interaction):
channel = interaction.channel
if not isinstance(channel, discord.Thread) or not isinstance(channel.parent, discord.ForumChannel):
await interaction.response.send_message("This command can only be used inside a forum post.", ephemeral=True)
return
owner = channel.guild.get_member(channel.owner_id)
if owner is None:
try:
owner = await channel.guild.fetch_member(channel.owner_id)
except discord.NotFound:
await interaction.response.send_message("Could not find the forum post owner.", ephemeral=True)
return
await interaction.response.send_message(f"Sorry {owner.mention} you have been denied to the SMP")
@deny.error
async def deny_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingPermissions):
await interaction.response.send_message("You do not have permission to use this command.", ephemeral=True)
@bot.tree.command(name="sorry", description="Let a forum post owner know the SMP is full.")
@app_commands.checks.has_permissions(manage_roles=True)
async def sorry(interaction: discord.Interaction):
channel = interaction.channel
if not isinstance(channel, discord.Thread) or not isinstance(channel.parent, discord.ForumChannel):
await interaction.response.send_message("This command can only be used inside a forum post.", ephemeral=True)
return
owner = channel.guild.get_member(channel.owner_id)
if owner is None:
try:
owner = await channel.guild.fetch_member(channel.owner_id)
except discord.NotFound:
await interaction.response.send_message("Could not find the forum post owner.", ephemeral=True)
return
await interaction.response.send_message(f"Sorry {owner.mention} we are full at the moment maybe next Season!")
@sorry.error
async def sorry_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingPermissions):
await interaction.response.send_message("You do not have permission to use this command.", ephemeral=True)