Shaun

make a discord bot named glxy bot

Kodari AI
KodariMon at 12:28 pm 1
GlxyBot
A Discord bot built with discord.py that provides modular server management features including moderation commands, role management, welcome messages, and custom prefix configuration. The bot includes a command handler system, event listeners for member joins and message activity, and utility commands for server administration. It supports asynchronous operation, error handling, and configurable settings stored in JSON. The bot is designed for easy extension with cogs and includes logging for monitoring bot activity and command usage across servers.
  1. Create the discord.py bot with branded slash commands and startup logging.

  2. Add its dependencies and a .env token placeholder.

  3. Keep it on default intents; no privileged intent is needed.

Created glxy bot with /glxy, /ping, and /help slash commands.

Set DISCORD_TOKEN in .env to your bot token. To make the bot’s actual Discord username glxy bot, set that name in the Discord Developer Portal; the code can’t change the account’s username.

Shaun

keep commands for ban kick and timeout

Kodari AI
KodariMon at 12:32 pm 1
  • Add /ban, /kick, and /timeout with permission checks, target/reason options, and clear success responses.

Added /ban, /kick, and /timeout (1–40,320 minutes), each with an optional reason and permission checks. The bot needs the matching moderation permissions, and its role must be above members it kicks or times out.

Shaun

make it so u can make a ticket

Kodari AI
KodariMon at 12:35 pm 1
  • Add /ticket to create a private channel, prevent duplicate open tickets, and include a close button.

  • Register the close button persistently and list /ticket in /help.

Added /ticket to create a private support channel, block duplicate open tickets, and provide a persistent Close ticket button. The ticket creator and roles with Manage Channels can access and close it. Make sure glxy bot has the Manage Channels permission.

Shaun

keep it that u can keep roles to other people and make roles

Kodari AI
KodariMon at 12:37 pm 1
  • Add /role create and /role give, restricted to members with Manage Roles.

  • Include both commands in /help and handle Discord permission or role-hierarchy failures.

Added /role create and /role give, and listed them in /help. Users need Manage Roles to run them; glxy bot also needs Manage Roles, and its role must be above the roles it assigns.

Shaun

make that only the owner of the server can acess the commands and let the roles which he chooses can only acces them

Kodari AI
KodariMon at 12:40 pm 1
  1. Persist each server’s approved access roles in access_roles.json.

  2. Add owner-only /access add, /access remove, and /access list.

  3. Restrict ban, kick, timeout, and role-management commands to the owner or approved roles; leave public commands and tickets available.

Restricted /ban, /kick, /timeout, /role create, and /role give to the server owner and roles the owner approves. The owner can manage the allowlist with /access add, /access remove, and /access list; it persists in access_roles.json. The bot still needs the relevant server permissions and role hierarchy to perform actions.

Shaun

all the role which i make should be in help

Kodari AI
KodariMon at 12:43 pm 1
  1. Update /help to list every non-@everyone role in the current server.

  2. Split long role lists into safe-sized ephemeral follow-up messages.

Updated /help to list every server role except @everyone, splitting long lists into multiple private messages. Role mentions are shown without pinging anyone.

Shaun

delete all of the commands

Kodari AI
KodariThu at 2:48 pm 2
  • Remove all bot commands and sync the empty command list with Discord.

  • Keep existing ticket close buttons working.

Removed all commands. Existing ticket close buttons will still work.

Shaun

remove all of them

Kodari AI
KodariThu at 2:48 pm 1
  • Remove the remaining ticket button handler.

  • Keep command syncing so Discord clears the deleted commands.

Removed the remaining ticket button handler. Existing ticket channels remain, but their close buttons will no longer work.

Shaun

change the bot name to cosmic bot all caps

Kodari AI
KodariThu at 2:49 pm 1
  • Rename the bot’s internal identifiers to COSMIC BOT.

  • Keep its startup and command syncing behavior unchanged.

Renamed the bot’s internal identifiers to COSMIC BOT. To change its visible Discord name, update the bot’s username in the Discord Developer Portal.

Shaun

keep ban timeout and kick also untimeout

Kodari AI
KodariThu at 2:50 pm 1
  • Add /ban, /kick, /timeout, and /untimeout with Discord permission checks.

  • Report permission and hierarchy errors privately.

Added /ban, /kick, /timeout, and /untimeout. Users and the bot need the corresponding Discord moderation permissions.

Shaun

un timout means remov ethe timeout from the member

Kodari AI
KodariThu at 2:51 pm 1

Yes — /untimeout removes the timeout from the selected member. It’s already set up that way.

Shaun

when i use /invite and i will send u a server link u should dm all of its members and ask them to join this serverhttps://discord.gg/EM3FFHUY5

Kodari AI
KodariThu at 2:52 pm 1

I can’t add a command that DMs every member of another server with unsolicited invites. A safer option is /invite that posts your invite in a channel where you have permission, or DMs members who explicitly opt in.

Shaun

remove / invite

Kodari AI
KodariThu at 2:53 pm 1

There’s no /invite command in the bot, so there’s nothing to remove.

Shaun

keep add roles and remove roles

Kodari AI
KodariThu at 2:54 pm 1
  • Add /role add and /role remove with permission and role-hierarchy checks.

  • Keep the existing moderation commands unchanged.

Added /role add and /role remove. Both the user and COSMIC BOT need Manage Roles, and the role must be below their respective highest roles.

Shaun

change the bots name from glxybot to COSMIC BOT

Kodari AI
KodariThu at 2:54 pm 1

The code already uses COSMIC BOT internally. To change the name people see on Discord, update the bot’s username in the Discord Developer Portal under Bot.

Shaun

can u make a command where u can advertise in differnt servers

Kodari AI
KodariThu at 2:57 pm 1
  • Add /advertise for posting in a chosen channel in the current server.

  • Require server management permission and check channel permissions.

Added /advertise to post a message in a channel in the current server. To advertise in another server, add COSMIC BOT there and use the command in an approved channel. The user needs Manage Server and permission to send messages there.

Shaun

no advertise to the members in dms

Kodari AI
KodariThu at 2:57 pm 1

I can’t add unsolicited advertising DMs to server members. I can make an opt-in command that lets members choose to receive announcements by DM.

Shaun

k

Kodari AI
KodariThu at 2:57 pm 1
  • Add server-specific opt-in and opt-out commands.

  • Send /advertise DMs only to opted-in members, with rate limiting and delivery results.

Added opt-in announcement DMs. Members can use /announcements_opt_in or /announcements_opt_out; server managers can use /advertise to message opted-in members.

Shaun

remove advertising commands

Kodari AI
KodariThu at 2:58 pm 1

Removed /advertise and the announcement opt-in and opt-out commands. They’ll be removed from Discord when the bot restarts and syncs its commands.

Kodari can make mistakes. Review important code before using.
Files
bot.py
requirements.txt
Code
2 137
bot.py
import logging
import os
from datetime import timedelta

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("cosmic_bot")


class CosmicBot(commands.Bot):
    def __init__(self) -> None:
        intents = discord.Intents.default()
        super().__init__(command_prefix=commands.when_mentioned, intents=intents, help_command=None)

    async def setup_hook(self) -> None:
        synced = await self.tree.sync()
        logger.info("Synced %d slash command(s)", len(synced))


bot = CosmicBot()


@bot.tree.command(name="ban", description="Ban a member from the server")
@app_commands.guild_only()
@app_commands.checks.has_permissions(ban_members=True)
@app_commands.checks.bot_has_permissions(ban_members=True)
async def ban(interaction: discord.Interaction, member: discord.Member, reason: str = "No reason provided") -> None:
    await member.ban(reason=f"{interaction.user}: {reason}")
    await interaction.response.send_message(f"Banned {member.mention}. Reason: {reason}", allowed_mentions=discord.AllowedMentions.none())


@bot.tree.command(name="kick", description="Kick a member from the server")
@app_commands.guild_only()
@app_commands.checks.has_permissions(kick_members=True)
@app_commands.checks.bot_has_permissions(kick_members=True)
async def kick(interaction: discord.Interaction, member: discord.Member, reason: str = "No reason provided") -> None:
    await member.kick(reason=f"{interaction.user}: {reason}")
    await interaction.response.send_message(f"Kicked {member.mention}. Reason: {reason}", allowed_mentions=discord.AllowedMentions.none())


@bot.tree.command(name="timeout", description="Timeout a member")
@app_commands.guild_only()
@app_commands.checks.has_permissions(moderate_members=True)
@app_commands.checks.bot_has_permissions(moderate_members=True)
async def timeout(interaction: discord.Interaction, member: discord.Member, minutes: app_commands.Range[int, 1, 40320], reason: str = "No reason provided") -> None:
    await member.timeout(timedelta(minutes=minutes), reason=f"{interaction.user}: {reason}")
    await interaction.response.send_message(f"Timed out {member.mention} for {minutes} minute(s). Reason: {reason}", allowed_mentions=discord.AllowedMentions.none())


@bot.tree.command(name="untimeout", description="Remove a member's timeout")
@app_commands.guild_only()
@app_commands.checks.has_permissions(moderate_members=True)
@app_commands.checks.bot_has_permissions(moderate_members=True)
async def untimeout(interaction: discord.Interaction, member: discord.Member, reason: str = "No reason provided") -> None:
    await member.timeout(None, reason=f"{interaction.user}: {reason}")
    await interaction.response.send_message(f"Removed the timeout for {member.mention}. Reason: {reason}", allowed_mentions=discord.AllowedMentions.none())


role_commands = app_commands.Group(name="role", description="Manage member roles", guild_only=True)


async def change_role(interaction: discord.Interaction, member: discord.Member, role: discord.Role, add: bool) -> None:
    guild = interaction.guild
    actor = interaction.user
    if role.is_default() or role.managed:
        await interaction.response.send_message("That role cannot be manually assigned or removed.", ephemeral=True)
        return
    if actor.id != guild.owner_id and role >= actor.top_role:
        await interaction.response.send_message("You can only manage roles below your highest role.", ephemeral=True)
        return
    if add:
        await member.add_roles(role, reason=f"Role added by {actor}")
        message = f"Added {role.mention} to {member.mention}."
    else:
        await member.remove_roles(role, reason=f"Role removed by {actor}")
        message = f"Removed {role.mention} from {member.mention}."
    await interaction.response.send_message(message, allowed_mentions=discord.AllowedMentions.none())


@role_commands.command(name="add", description="Add a role to a member")
@app_commands.checks.has_permissions(manage_roles=True)
@app_commands.checks.bot_has_permissions(manage_roles=True)
async def role_add(interaction: discord.Interaction, member: discord.Member, role: discord.Role) -> None:
    await change_role(interaction, member, role, True)


@role_commands.command(name="remove", description="Remove a role from a member")
@app_commands.checks.has_permissions(manage_roles=True)
@app_commands.checks.bot_has_permissions(manage_roles=True)
async def role_remove(interaction: discord.Interaction, member: discord.Member, role: discord.Role) -> None:
    await change_role(interaction, member, role, False)


bot.tree.add_command(role_commands)


@bot.tree.error
async def on_app_command_error(interaction: discord.Interaction, error: app_commands.AppCommandError) -> None:
    if isinstance(error, app_commands.MissingPermissions):
        message = "You don't have permission to use this command."
    elif isinstance(error, app_commands.BotMissingPermissions):
        message = "I don't have the permissions needed to do that."
    elif isinstance(error, app_commands.CommandOnCooldown):
        message = f"Please wait {error.retry_after:.0f} seconds before using this command again."
    elif isinstance(error, app_commands.CommandInvokeError) and isinstance(error.original, discord.Forbidden):
        message = "Discord denied that action. Check my permissions and role hierarchy."
    else:
        logger.error("Slash command failed", exc_info=(type(error), error, error.__traceback__))
        message = "The command failed. Please try again."
    if interaction.response.is_done():
        await interaction.followup.send(message, ephemeral=True)
    else:
        await interaction.response.send_message(message, ephemeral=True)


@bot.event
async def on_ready() -> None:
    logger.info("Logged in as %s", bot.user)
    print("KODARI_READY", flush=True)


token = os.getenv("DISCORD_TOKEN")
if not token or token == "your_discord_bot_token_here":
    raise RuntimeError("Set DISCORD_TOKEN in .env to your Discord bot token.")

bot.run(token, log_handler=None)