iljuha2907876

add this code to my bot

πŸ“Ž 1 file 1,913 chars
πŸ“„
pasted-code-1792872307257.txt
txt 55 lines
β–Ά
# badge_simulator.py
import discord
from discord.ext import commands

# --- CONFIG ---
TOKEN = "YOUR_BOT_TOKEN"  # Replace with your bot token
PREFIX = "!"
INTENTS = discord.Intents.default()

# --- BOT SETUP ---
bot = commands.Bot(command_prefix=PREFIX, intents=INTENTS)

# Predefined badge list (visual only)
BADGES = {
    "staff": {"emoji": "πŸ›‘οΈ", "description": "Discord Staff"},
    "hypesquad_bravery": {"emoji": "🏠", "description": "HypeSquad House of Bravery"},
    "hypesquad_balance": {"emoji": "βš–οΈ", "description": "HypeSquad House of Balance"},
    "hypesquad_harmony": {"emoji": "🎢", "description": "HypeSquad House of Harmony"},
    "bug_hunter": {"emoji": "πŸ”", "description": "Discord Bug Hunter"},
    "nitro": {"emoji": "πŸ’Ž", "description": "Discord Nitro Subscriber"},
    "early_supporter": {"emoji": "🌟", "description": "Early Supporter"},
    "server_booster": {"emoji": "πŸš€", "description": "Server Booster"},
}

@bot.event
async def on_ready():
    print(f"βœ… Logged in as {bot.user} (ID: {bot.user.id})")
    print("πŸ’‘ Use !badges to display badge showcase.")

@bot.command()
async def badges(ctx):
    """Displays a visual showcase of badges."""
    embed = discord.Embed(
        title="πŸŽ– Discord Badge Showcase",
        description="Visual-only badge simulator (safe & ToS-compliant)",
        color=0x7289DA
    )

    for badge_name, badge_info in BADGES.items():
        embed.add_field(
            name=f"{badge_info['emoji']} {badge_info['description']}",
            value=f"ID: `{badge_name}`",
            inline=False
        )

    embed.set_footer(text="This is a simulation β€” no real badge granting.")
    await ctx.send(embed=embed)

# Run the bot
if __name__ == "__main__":
    try:
        bot.run(TOKEN)
    except discord.LoginFailure:
        print("❌ Invalid bot token. Please check your TOKEN variable.")
Kodari AI
KodariOct 24 at 8:06 pm 1
BadgeShowcaseBot
A Discord bot that displays a visual-only badge showcase. It uses a predefined dictionary of badge names, emojis, and descriptions to create an embedded message. The bot responds to the "!badges" command, presenting an informative embed with each badge's emoji, description, and ID. It emphasizes that this is a simulation and does not grant real badges, ensuring ToS compliance. The bot includes error handling for invalid tokens and logs in successfully with a confirmation message.
  • Add a main.py with the badge showcase as a /badges slash command.

  • Add requirements.txt and a .env token placeholder.

  • Use default intents, logging, and the required KODARI_READY startup line.

Created main.py with a /badges slash command and the visual-only badge showcase, plus requirements.txt and a .env placeholder. Add your bot token to .env as DISCORD_TOKEN=..., install the requirements, and start the bot. The slash command syncs on startup; no privileged intents are needed.

iljuha2907876

and make it so i can give the badges

Kodari AI
KodariOct 24 at 8:12 pm 1
  1. Add admin-only /givebadge and /removebadge commands for server members.

  2. Persist assignments across restarts and let /badges show a member’s simulated badges.

Added /givebadge and /removebadge for members with Manage Server permission. Use /badges with a member to view their assigned badges; assignments persist across restarts.

These badges are visual-only server simulations. Discord’s actual profile badges can’t be granted by a bot.

Kodari can make mistakes. Review important code before using.
Files
main.py
requirements.txt
Code
2 209
main.py
import json
import logging
import os
from pathlib import Path

import discord
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("badge_simulator")
BADGE_ASSIGNMENTS_FILE = Path("badge_assignments.json")

BADGES = {
    "staff": {"emoji": "πŸ›‘οΈ", "description": "Discord Staff"},
    "hypesquad_bravery": {"emoji": "🏠", "description": "HypeSquad House of Bravery"},
    "hypesquad_balance": {"emoji": "βš–οΈ", "description": "HypeSquad House of Balance"},
    "hypesquad_harmony": {"emoji": "🎢", "description": "HypeSquad House of Harmony"},
    "bug_hunter": {"emoji": "πŸ”", "description": "Discord Bug Hunter"},
    "nitro": {"emoji": "πŸ’Ž", "description": "Discord Nitro Subscriber"},
    "early_supporter": {"emoji": "🌟", "description": "Early Supporter"},
    "server_booster": {"emoji": "πŸš€", "description": "Server Booster"},
    "Partnered Server Owner": {"emoji": "♻️", "description": "Given to owners of partnered Discord servers."},
}

BADGE_CHOICES = [
    discord.app_commands.Choice(name=badge_info["description"], value=badge_name)
    for badge_name, badge_info in BADGES.items()
]


def load_badge_assignments() -> dict[str, dict[str, list[str]]]:
    try:
        return json.loads(BADGE_ASSIGNMENTS_FILE.read_text(encoding="utf-8"))
    except FileNotFoundError:
        return {}
    except (OSError, json.JSONDecodeError):
        logger.exception("Could not load badge assignments")
        return {}


def save_badge_assignments() -> None:
    BADGE_ASSIGNMENTS_FILE.write_text(
        json.dumps(badge_assignments, indent=2),
        encoding="utf-8",
    )


badge_assignments = load_badge_assignments()


class BadgeBot(commands.Bot):
    async def setup_hook(self) -> None:
        try:
            synced = await self.tree.sync()
            logger.info("Synced %d application command(s)", len(synced))
        except discord.HTTPException:
            logger.exception("Failed to sync application commands")
            raise


bot = BadgeBot(command_prefix="!", intents=discord.Intents.default())


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


@bot.tree.command(name="badges", description="Show the badge catalog or a member's simulated badges")
async def badges(
    interaction: discord.Interaction,
    member: discord.Member | None = None,
) -> None:
    """Display the visual-only badge catalog or a member's assigned badges."""
    if member is not None:
        if interaction.guild is None:
            await interaction.response.send_message(
                "Member badges can only be viewed in a server.",
                ephemeral=True,
            )
            return

        assigned_badges = badge_assignments.get(str(interaction.guild.id), {}).get(
            str(member.id), []
        )
        embed = discord.Embed(
            title=f"πŸŽ– {member.display_name}'s Simulated Badges",
            color=0x7289DA,
        )
        if assigned_badges:
            embed.description = "\n".join(
                f"{BADGES[badge_name]['emoji']} {BADGES[badge_name]['description']}"
                for badge_name in assigned_badges
                if badge_name in BADGES
            )
        else:
            embed.description = "This member has no simulated badges."
        embed.set_footer(text="These are visual-only and do not change Discord profile badges.")
        await interaction.response.send_message(embed=embed)
        return

    embed = discord.Embed(
        title="πŸŽ– Discord Badge Showcase",
        description="Visual-only badge catalog. Server admins can assign these with /givebadge.",
        color=0x7289DA,
    )

    for badge_name, badge_info in BADGES.items():
        embed.add_field(
            name=f"{badge_info['emoji']} {badge_info['description']}",
            value=f"ID: `{badge_name}`",
            inline=False,
        )

    embed.set_footer(text="This is a simulation β€” no real Discord profile badges are granted.")
    await interaction.response.send_message(embed=embed)


@bot.tree.command(name="givebadge", description="Give a member a simulated badge")
@discord.app_commands.guild_only()
@discord.app_commands.checks.has_permissions(manage_guild=True)
@discord.app_commands.choices(badge=BADGE_CHOICES)
async def give_badge(
    interaction: discord.Interaction,
    member: discord.Member,
    badge: discord.app_commands.Choice[str],
) -> None:
    guild_badges = badge_assignments.setdefault(str(interaction.guild_id), {})
    member_badges = guild_badges.setdefault(str(member.id), [])
    if badge.value in member_badges:
        await interaction.response.send_message(
            f"{member.mention} already has the simulated {BADGES[badge.value]['description']} badge.",
            ephemeral=True,
        )
        return

    member_badges.append(badge.value)
    save_badge_assignments()
    await interaction.response.send_message(
        f"Gave {member.mention} the simulated {BADGES[badge.value]['description']} badge."
    )


@bot.tree.command(name="removebadge", description="Remove a simulated badge from a member")
@discord.app_commands.guild_only()
@discord.app_commands.checks.has_permissions(manage_guild=True)
@discord.app_commands.choices(badge=BADGE_CHOICES)
async def remove_badge(
    interaction: discord.Interaction,
    member: discord.Member,
    badge: discord.app_commands.Choice[str],
) -> None:
    guild_key = str(interaction.guild_id)
    member_key = str(member.id)
    member_badges = badge_assignments.get(guild_key, {}).get(member_key, [])
    if badge.value not in member_badges:
        await interaction.response.send_message(
            f"{member.mention} does not have the simulated {BADGES[badge.value]['description']} badge.",
            ephemeral=True,
        )
        return

    member_badges.remove(badge.value)
    if not member_badges:
        badge_assignments[guild_key].pop(member_key, None)
    if not badge_assignments.get(guild_key):
        badge_assignments.pop(guild_key, None)
    save_badge_assignments()
    await interaction.response.send_message(
        f"Removed the simulated {BADGES[badge.value]['description']} badge from {member.mention}."
    )


@bot.tree.error
async def on_app_command_error(
    interaction: discord.Interaction,
    error: discord.app_commands.AppCommandError,
) -> None:
    logger.error(
        "Application command failed",
        exc_info=(type(error), error, error.__traceback__),
    )
    message = "The command failed. Please try again later."
    if isinstance(error, discord.app_commands.MissingPermissions):
        message = "You need the Manage Server permission to assign or remove simulated badges."
    if interaction.response.is_done():
        await interaction.followup.send(message, ephemeral=True)
    else:
        await interaction.response.send_message(message, ephemeral=True)


if __name__ == "__main__":
    token = os.getenv("DISCORD_TOKEN")