D

can you make me a discord server for me and my friends add (loft music), (Gaming chats) and roles

Kodari AI
KodariSep 5 at 10:19 pm 1
FriendZoneDiscord
A Discord bot that creates and configures a server for friends, automatically setting up text channels for Loft Music and Gaming Chats, plus role management. The bot uses discord.py to create categories, channels, and assign roles like Admin, Moderator, and Member, providing a ready-to-use social gaming community hub.
  1. Create a Discord bot with secure .env token loading and logging.

  2. Add an administrator-only /setup-server command that creates Loft Music, Gaming Chats, and standard friend-server roles/channels.

  3. Add dependency/configuration files and setup instructions.

Created a Discord server setup bot with:

  • /setup-server administrator command

  • Loft Music category with #loft-music and Music Lounge

  • Gaming Chats category with #gaming-chat and Gaming Lobby

  • Welcome category with #welcome and #rules

  • Roles: Admin, Moderator, Gamer, Music Lover, and Member

  • .env token loading

  • Permission checks, cooldowns, logging, and error handling

  • Setup instructions in README.md

Run it with:

Shell
pip install -r requirements.txt
cp .env.example .env
python bot.py

Then invite the bot with Manage Channels, Manage Roles, and Send Messages permissions, and run /setup-server in your Discord server.

D

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

Kodari AI
KodariSep 5 at 10:22 pm 1

That appears to be a GitHub personal access token. Treat it as compromised because it was shared publicly here.

  1. Revoke it immediately: GitHub → Settings → Developer settings → Personal access tokens → locate it → Delete/Revoke.

  2. Create a new token only if needed, with the minimum required permissions and an expiration date.

  3. Check GitHub security/audit logs for unauthorized use.

  4. Remove the exposed token from .env, source code, logs, and Git history if it was committed.

  5. Store the replacement in a local .env file or secret manager—never paste it into chat or commit it.

I won’t use or retain the token.

Kodari can make mistakes. Review important code before using.
Files
.gitignore
bot.py
README.md
requirements.txt
Code
4 300
bot.py
import logging
import os

import discord
from discord import app_commands
from discord.ext import commands
from dotenv import load_dotenv


load_dotenv()

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
)
logger = logging.getLogger("friends-server-bot")


class FriendsServerBot(commands.Bot):
    def __init__(self) -> None:
        intents = discord.Intents.default()
        intents.guilds = True
        super().__init__(command_prefix="!", intents=intents)

    async def setup_hook(self) -> None:
        await self.tree.sync()
        logger.info("Application commands synced")

    async def on_ready(self) -> None:
        if self.user is not None:
            logger.info("Logged in as %s (%s)", self.user, self.user.id)


bot = FriendsServerBot()


def find_role(guild: discord.Guild, name: str) -> discord.Role | None:
    return discord.utils.get(guild.roles, name=name)


def find_category(guild: discord.Guild, name: str) -> discord.CategoryChannel | None:
    return discord.utils.get(guild.categories, name=name)


async def get_or_create_role(
    guild: discord.Guild,
    name: str,
    colour: discord.Colour,
) -> tuple[discord.Role, bool]:
    role = find_role(guild, name)
    if role is not None:
        return role, False

    return await guild.create_role(
        name=name,
        colour=colour,
        reason="Friends server setup",
    ), True


async def get_or_create_category(
    guild: discord.Guild,
    name: str,
) -> tuple[discord.CategoryChannel, bool]:
    category = find_category(guild, name)
    if category is not None:
        return category, False

    return await guild.create_category(name, reason="Friends server setup"), True


async def get_or_create_text_channel(
    category: discord.CategoryChannel,
    name: str,
    topic: str | None = None,
) -> tuple[discord.TextChannel, bool]:
    channel = discord.utils.get(category.text_channels, name=name)
    if channel is not None:
        return channel, False

    return await category.create_text_channel(
        name,
        topic=topic,
        reason="Friends server setup",
    ), True


async def get_or_create_voice_channel(
    category: discord.CategoryChannel,
    name: str,
) -> tuple[discord.VoiceChannel, bool]:
    channel = discord.utils.get(category.voice_channels, name=name)
    if channel is not None:
        return channel, False

    return await category.create_voice_channel(
        name,
        reason="Friends server setup",
    ), True


@bot.tree.command(name="setup-server", description="Create the friend-server channels and roles")
@app_commands.checks.has_permissions(administrator=True)
@app_commands.checks.cooldown(1, 30.0)
async def setup_server(interaction: discord.Interaction) -> None:
    guild = interaction.guild
    if guild is None:
        await interaction.response.send_message(
            "This command can only be used inside a server.",
            ephemeral=True,
        )
        return

    await interaction.response.defer(ephemeral=True)

    try:
        role_definitions = (
            ("Admin", discord.Colour.red()),
            ("Moderator", discord.Colour.blue()),
            ("Gamer", discord.Colour.green()),
            ("Music Lover", discord.Colour.purple()),
            ("Member", discord.Colour.light_grey()),
        )
        role_results = [
            await get_or_create_role(guild, name, colour)
            for name, colour in role_definitions
        ]

        welcome_category, welcome_category_created = await get_or_create_category(
            guild, "Welcome"
        )
        welcome_channel, welcome_channel_created = await get_or_create_text_channel(
            welcome_category,
            "welcome",
            "Welcome to the server! Read the rules and say hello.",
        )
        rules_channel, rules_channel_created = await get_or_create_text_channel(
            welcome_category,
            "rules",
            "Server rules and guidelines.",
        )

        music_category, music_category_created = await get_or_create_category(
            guild, "Loft Music"
        )
        music_channel, music_channel_created = await get_or_create_text_channel(
            music_category,
            "loft-music",
            "Share songs, playlists, and music recommendations.",
        )
        music_voice, music_voice_created = await get_or_create_voice_channel(
            music_category, "Music Lounge"
        )

        gaming_category, gaming_category_created = await get_or_create_category(
            guild, "Gaming Chats"
        )
        gaming_channel, gaming_channel_created = await get_or_create_text_channel(
            gaming_category,
            "gaming-chat",
            "Talk about games and find people to play with.",
        )
        gaming_voice, gaming_voice_created = await get_or_create_voice_channel(
            gaming_category, "Gaming Lobby"
        )

        created_roles = sum(created for _, created in role_results)
        created_channels = sum(
            (
                welcome_category_created,
                welcome_channel_created,
                rules_channel_created,
                music_category_created,
                music_channel_created,
                music_voice_created,
                gaming_category_created,
                gaming_channel_created,
                gaming_voice_created,
            )
        )

        await welcome_channel.send(
            "Welcome to the server! Check <#{}> and then introduce yourself.".format(
                rules_channel.id
            )
        )
        await rules_channel.send(
            "Be respectful, keep chat friendly, and have fun."
        )

        await interaction.followup.send(
            "Server setup complete. Created {} role(s) and {} channel/category item(s).\n"
            "Added: **Loft Music** with `#loft-music` and **Music Lounge`; "
            "**Gaming Chats** with `#gaming-chat` and **Gaming Lobby`.".format(
                created_roles, created_channels
            ),
            ephemeral=True,
        )
        logger.info("Server setup completed for guild %s (%s)", guild.name, guild.id)
    except discord.Forbidden: