Files
image_gen.py
main.py
planner.py
README.md
requirements.txt
templates.py
Code
6 1,308
main.py
import os
import asyncio
import io
import discord
from discord.ext import commands
from dotenv import load_dotenv
import planner
import templates as tmpl
from image_gen import generate_role_icon
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
intents = discord.Intents.default()
intents.message_content = True
intents.guilds = True
bot = commands.Bot(command_prefix="!", intents=intents, help_command=None)
SETUP_SESSIONS: dict[int, str] = {}
@bot.event
async def on_ready():
print(f"[MCSetupBot] Logged in as {bot.user} (ID: {bot.user.id})")
print(f"[MCSetupBot] Connected to {len(bot.guilds)} guild(s)")
try:
synced = await bot.tree.sync()
print(f"[MCSetupBot] Synced {len(synced)} slash command(s)")
except Exception as e:
print(f"[MCSetupBot] Slash sync failed: {e}")
def build_plan_embed(plan: dict, guild_name: str) -> discord.Embed:
embed = discord.Embed(
title=f"📋 Server Setup Plan — {plan['template_name']}",
description=(
f"**Server:** {guild_name}\n"
f"**Template:** {plan['template_name']}\n\n"
f"_{plan['description']}_\n\n"
f"🎨 **Color Palette Rationale:**\n{plan['color_palette_reason']}"
),
color=discord.Color.blurple(),
)
role_lines = [f"`{r['name']}` — `{r['color']}`" for r in plan["roles"]]
roles_text = "\n".join(role_lines)
if len(roles_text) > 1024:
roles_text = roles_text[:1020] + "..."
embed.add_field(name="🎭 Roles & Colors", value=roles_text, inline=False)
steps = planner.build_numbered_steps(plan)
current_chunk = ""
chunks = []
for line in steps:
if len(current_chunk) + len(line) + 1 > 1024:
chunks.append(current_chunk.strip())
current_chunk = line + "\n"
else:
current_chunk += line + "\n"
if current_chunk.strip():
chunks.append(current_chunk.strip())
for i, chunk in enumerate(chunks):
label = "📝 Execution Steps" if i == 0 else "📝 Execution Steps (cont.)"
embed.add_field(name=label, value=chunk, inline=False)
embed.set_footer(
text="✅ !confirm to execute | 🗑️ !cancel to abort | ✏️ !change [description] to edit"
)
return embed
@bot.command(name="setup")
@commands.has_permissions(administrator=True)
async def setup(ctx: commands.Context):
guild_id = ctx.guild.id
if planner.has_pending_plan(guild_id):
await ctx.send(
"⚠️ You already have a pending plan!\n"
"• Type `!confirm` to execute it\n"
"• Type `!cancel` to discard it\n"
"• Type `!change [description]` to modify it\n"
"• Type `!viewplan` to review it again"
)
return
embed = discord.Embed(
title="🏗️ Minecraft Discord Server Setup",
description=(
"Welcome! I'll design a **professional, creative Discord server structure** "
"tailored to your Minecraft community.\n\n"
"**Choose your server type:**\n\n"
"```\n"
"1. ⛏️ Survival SMP — Cozy community survival\n"
"2. ⚔️ Factions PvP — Competitive warzone server\n"
"3. 🔧 Modded / Forge — Technical modded gameplay\n"
"4. 🎨 Creative Building — Art and architecture focus\n"
"5. 🌐 Full Network — Multi-gamemode large server\n"
"```\n"
"Reply with a **number (1–5)** or the server type name."
),
color=discord.Color.green(),
)
await ctx.send(embed=embed)
SETUP_SESSIONS[guild_id] = "awaiting_type"
@bot.event
async def on_message(message: discord.Message):
if message.author.bot:
return
await bot.process_commands(message)
if not message.guild:
return
guild_id = message.guild.id
if guild_id in SETUP_SESSIONS and SETUP_SESSIONS[guild_id] == "awaiting_type":
if message.content.startswith("!"):
return
type_map = {
"1": "survival",
"survival": "survival",
"survival smp": "survival",
"smp": "survival",
"2": "factions",
"factions": "factions",
"factions pvp": "factions",
"pvp": "factions",
"3": "modded",
"modded": "modded",
"forge": "modded",
"fabric": "modded",
"modded/forge": "modded",
"modded forge": "modded",
"4": "creative",
"creative": "creative",
"creative building": "creative",
"building": "creative",
"5": "network",
"network": "network",
"full network": "network",
}
chosen = type_map.get(message.content.strip().lower())
if not chosen:
await message.channel.send(
"❓ I didn't recognize that choice. Please type a number **1–5** or a name like "
"`Survival SMP`, `Factions`, `Modded`, `Creative`, or `Network`."
)
return
del SETUP_SESSIONS[guild_id]
thinking_msg = await message.channel.send("⏳ Generating your custom server plan...")
plan = planner.create_plan_from_template(chosen)
planner.set_pending_plan(guild_id, plan)
embed = build_plan_embed(plan, message.guild.name)
await thinking_msg.delete()
await message.channel.send(
content=(
"✨ **Here's the custom server structure I've designed for you!**\n"
"Review every detail carefully. When you're ready, type `!confirm` to execute it."
),
embed=embed,
)
@bot.command(name="confirm")
@commands.has_permissions(administrator=True)
async def confirm(ctx: commands.Context):
guild_id = ctx.guild.id
plan = planner.get_pending_plan(guild_id)
if not plan:
await ctx.send("❌ No pending plan found. Run `!setup` first.")
return
planner.clear_pending_plan(guild_id)
SETUP_SESSIONS.pop(guild_id, None)
progress_msg = await ctx.send("🚀 **Executing your server setup plan...**\nCreating roles and channels now.")
log_lines: list[str] = []
async def progress_callback(text: str):
log_lines.append(text)
display = "\n".join(log_lines[-20:])
try:
await progress_msg.edit(content=f"⚙️ **Setup in progress...**\n\n{display}")
except discord.HTTPException:
pass