Files
cogs
utils
config.json
main.py
requirements.txt
Code
7 412
main.py
import os
import asyncio
import discord
from discord.ext import commands
from dotenv import load_dotenv
from utils import rules_manager
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
if not TOKEN or TOKEN == "your_discord_bot_token_here":
print("❌ ERROR: No DISCORD_TOKEN found in .env file.")
print(" 1. Open the .env file")
print(" 2. Replace 'your_discord_bot_token_here' with your actual bot token")
print(" 3. Save the file and run again")
exit(1)
intents = discord.Intents.all()
bot = commands.Bot(
command_prefix="!",
intents=intents,
help_command=None
)
@bot.event
async def on_ready():
print(f"✅ Logged in as {bot.user} (ID: {bot.user.id})")
print(f"🌐 Serving {len(bot.guilds)} guild(s)")
print("─" * 40)
@bot.event
async def on_guild_join(guild):
rules_manager.get_guild_data(guild.id)
channel = guild.system_channel
if channel and channel.permissions_for(guild.me).send_messages:
embed = discord.Embed(
title="👋 Thanks for adding me!",
description=(
"I help manage server rules. Here's how to get started:\n\n"
"1. **Add rules** — `!ruleset add <rule text>`\n"
"2. **View rules** — `!rules`\n"
"3. **Set a channel** — `!ruleset channel #channel`\n"
"4. **Set agreement role** — `!ruleset role @role`\n"
"5. **Enable acceptance** — `!ruleset agree on`\n\n"
"Use `!help` for all commands."
),
color=discord.Color.green()
)
await channel.send(embed=embed)
@bot.command(name="help")
async def help_command(ctx):
embed = discord.Embed(
title="📜 DiscordRuleManager — Commands",
description="Manage and display server rules easily.",
color=discord.Color.green()
)
embed.add_field(name="!rules", value="Show all server rules", inline=False)
embed.add_field(name="!rule <number>", value="Show a specific rule", inline=False)
embed.add_field(name="!accept", value="Accept the server rules", inline=False)
embed.add_field(name="!ruleset", value="Admin rule management panel", inline=False)
embed.add_field(name="!ruleset add <text>", value="Add a new rule (Admin)", inline=False)
embed.add_field(name="!ruleset remove <num>", value="Remove a rule (Admin)", inline=False)
embed.add_field(name="!ruleset edit <num> <text>", value="Edit a rule (Admin)", inline=False)
embed.add_field(name="!ruleset channel <#ch>", value="Set rules channel (Admin)", inline=False)
embed.add_field(name="!ruleset role <@role>", value="Set accept role (Admin)", inline=False)
embed.add_field(name="!ruleset agree on/off", value="Toggle acceptance (Admin)", inline=False)
embed.add_field(name="!ruleset reload", value="Reload from file (Admin)", inline=False)
embed.set_footer(text=f"{bot.user.name} • Made with discord.py")
await ctx.send(embed=embed)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
return
if isinstance(error, commands.NotOwner):
return
raise error
async def main():
await bot.load_extension("cogs.rules")
async with bot:
await bot.start(TOKEN)
if __name__ == "__main__":
asyncio.run(main())