jaxfoxx

can u make me a bot that i can make a certain discord role a gift and i can also add certain roles to be % gift rewards and make a command like /open gift to remove the gift role and give the user a reward role by how high or how low the % is

Kodari AI
KodariOct 6 at 5:55 am 1
GiftRoleRewards
A Discord bot for managing gift roles and percentage-based reward roles. Admins can designate a specific role as a gift, configure multiple reward roles with custom drop percentages, and users can redeem via /open gift command. The bot removes the gift role and randomly assigns a reward role based on configured probabilities, with higher percentages having greater chances. Includes slash commands for setup, role configuration, and redemption tracking.

Created the bot with /gift role set, /gift reward add, /gift reward remove, /gift reward list, and /open gift. Reward chances are percentage-based; if they total less than 100%, the remaining chance means no reward.

Add your bot token to .env, then invite the bot with Manage Roles permission and place its highest role above the gift and reward roles. The bot uses no privileged intents.

jaxfoxx

make it so i can add more then one gift

Kodari AI
KodariOct 6 at 6:14 am 1
  1. Store multiple gift role IDs while migrating existing single-role settings.

  2. Add /gift role add, /gift role remove, and /gift role list.

  3. Make /open gift consume one of the gift roles the member has.

Added support for multiple gift roles. Admins can use /gift role add, /gift role remove, and /gift role list. /open gift consumes one configured gift role the member has; existing single-role settings are migrated automatically.

jaxfoxx

make it so I can pick the gift I want to open with a menu and make it so I can add rewards to certain gifts with a menu

Kodari AI
KodariOct 6 at 6:21 am 1
  1. Add a gift-selection menu to /open gift.

  2. Add a menu flow for assigning reward roles to a selected gift.

/open gift now shows a menu to choose which gift to open. /gift reward add lets admins choose a gift, select a reward role, and enter its chance; /gift reward remove and /gift reward list are also gift-specific. Existing reward settings are migrated to each configured gift.

jaxfoxx

make it so u always get a reward

Kodari AI
KodariOct 6 at 7:20 am 1

I’ll choose randomly among the gift’s positive-chance rewards, weighted by their configured percentages, and keep the gift untouched if no eligible reward is configured.

/open gift now always awards a reward when that gift has at least one configured reward with a positive chance. The percentages set relative odds; if no positive-chance reward is available, the gift isn’t consumed.

jaxfoxx

add a role trading system where members can send trades to each other and trade role make it so the owner has to set certain roles to be traderble

Kodari AI
KodariOct 6 at 8:40 am 1

[Generation stopped]

jaxfoxx

add a role trading system where members can send trades to each other and trade role make it so the owner has to set certain roles to be tradeable make it all this menus

Kodari AI
KodariOct 6 at 8:42 am 1
  1. Add owner-managed tradeable-role settings and all-menu controls.

  2. Add member-to-member trade offers, accept/decline menus, and safe role swapping.

Added an all-menu role trading system:

  • The server owner configures eligible roles with /trade manage → Add, Remove, or List tradeable roles.

  • Members use /trade offer to choose another member, a role to offer, and a role they want in return.

  • Only the recipient can accept or decline. Accepting exchanges the roles after checking they’re still tradeable and both members still have them.

The bot needs Manage Roles, and its highest role must be above every role the owner allows to be traded.

jaxfoxx

add a command that lets u check who traded u and make it so in /trade manage i can select more then one role at a time to make tradeable

Kodari AI
KodariOct 6 at 8:51 am 1
  1. Add a command to view recent trades involving you.

  2. Update /trade manage so roles can be selected and configured in batches.

Added /trade history to show your 10 most recent completed trades, including who you traded with and which roles were exchanged.

In /trade manage, you can now select multiple roles at once when adding or removing tradeable roles.

jaxfoxx

change the maximum of 25 roles can be tradeable to 250 and make the menus have pages

Kodari AI
KodariOct 6 at 9:04 am 1
  1. Raise the tradeable-role cap to 250.

  2. Add pagination to role menus so larger lists remain usable.

/trade manage now allows up to 250 tradeable roles. Role menus are paginated in groups of 25, including the tradeable-role list, role removal, and role choices in trade offers.

jaxfoxx

let me scroll up and down to look at all the tradeable role i have and the person i am trading

Kodari AI
KodariOct 6 at 9:15 am 1
  1. Keep the selected trading partner visible while browsing your roles.

  2. Label role-page controls as scroll up/down so it’s clear how to browse every page.

Updated the trade menus: role pages now have ⬆️ Scroll up and ⬇️ Scroll down controls, and the selected trading partner stays visible while you browse roles to offer.

Kodari can make mistakes. Review important code before using.
Files
.gitignore
bot.py
requirements.txt
Code
3 1,208
bot.py
import json
import logging
import os
import random
import asyncio
import time
from pathlib import Path

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("gift_bot")
DATA_FILE = Path("gift_settings.json")


def load_settings() -> dict[str, dict]:
    if not DATA_FILE.exists():
        return {}
    try:
        with DATA_FILE.open("r", encoding="utf-8") as settings_file:
            settings = json.load(settings_file)
        return settings if isinstance(settings, dict) else {}
    except (OSError, json.JSONDecodeError):
        logger.exception("Could not load gift settings")
        return {}


settings = load_settings()


def save_settings() -> None:
    with DATA_FILE.open("w", encoding="utf-8") as settings_file:
        json.dump(settings, settings_file, indent=2)


def guild_settings(guild_id: int) -> dict:
    data = settings.setdefault(str(guild_id), {"gift_roles": [], "gift_rewards": {}})
    data.setdefault("tradeable_roles", [])
    data.setdefault("trade_history", [])
    if "gift_roles" not in data:
        legacy_role = data.pop("gift_role", None)
        data["gift_roles"] = [legacy_role] if legacy_role else []
    else:
        data.pop("gift_role", None)
    if "gift_rewards" not in data:
        legacy_rewards = data.pop("rewards", {})
        data["gift_rewards"] = {
            str(role_id): dict(legacy_rewards) for role_id in data["gift_roles"]
        }
    else:
        data.pop("rewards", None)
    return data


def can_manage_role(guild: discord.Guild, role: discord.Role) -> bool:
    bot_member = guild.me
    return bool(
        bot_member
        and bot_member.guild_permissions.manage_roles
        and role.is_assignable()
    )


def is_admin(interaction: discord.Interaction) -> bool:
    return bool(
        interaction.guild
        and isinstance(interaction.user, discord.Member)
        and interaction.user.guild_permissions.manage_roles
    )


class GiftBot(commands.Bot):
    async def setup_hook(self) -> None:
        await self.tree.sync()


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

gift_group = app_commands.Group(name="gift", description="Configure gift roles")
gift_role_group = app_commands.Group(
    name="role", description="Configure gift roles", parent=gift_group
)
gift_reward_group = app_commands.Group(
    name="reward", description="Configure gift reward roles", parent=gift_group
)
open_group = app_commands.Group(name="open", description="Open your gift")
trade_group = app_commands.Group(name="trade", description="Trade approved roles")


@gift_role_group.command(name="add", description="Add a role members can use to open a gift")
@app_commands.describe(role="The role members can use to open a gift")
@app_commands.guild_only()
async def add_gift_role(interaction: discord.Interaction, role: discord.Role) -> None:
    if not is_admin(interaction):
        await interaction.response.send_message(
            "You need the Manage Roles permission to configure gifts.", ephemeral=True
        )
        return

    if not can_manage_role(interaction.guild, role):
        await interaction.response.send_message(
            "I need the Manage Roles permission, and my highest role must be above that role.",
            ephemeral=True,
        )
        return

    data = guild_settings(interaction.guild_id)
    if any(
        str(role.id) in rewards
        for rewards in data["gift_rewards"].values()
    ):
        await interaction.response.send_message(
            "That role is already configured as a reward. Remove it as a reward first.",
            ephemeral=True,
        )
        return

    if role.id in data["gift_roles"]:
        await interaction.response.send_message(
            f"{role.mention} is already configured as a gift role.", ephemeral=True
        )
        return

    data["gift_roles"].append(role.id)
    save_settings()
    await interaction.response.send_message(f"Added {role.mention} as a gift role.", ephemeral=True)


@gift_role_group.command(name="remove", description="Remove a role from the gift roles")
@app_commands.describe(role="The gift role to remove")
@app_commands.guild_only()
async def remove_gift_role(interaction: discord.Interaction, role: discord.Role) -> None:
    if not is_admin(interaction):
        await interaction.response.send_message(
            "You need the Manage Roles permission to configure gifts.", ephemeral=True
        )
        return

    gift_roles = guild_settings(interaction.guild_id)["gift_roles"]
    if role.id not in gift_roles:
        await interaction.response.send_message(
            f"{role.mention} is not configured as a gift role.", ephemeral=True
        )
        return

    gift_roles.remove(role.id)
    guild_settings(interaction.guild_id)["gift_rewards"].pop(str(role.id), None)
    save_settings()
    await interaction.response.send_message(f"Removed {role.mention} from gift roles.", ephemeral=True)


@gift_role_group.command(name="list", description="List configured gift roles")
@app_commands.guild_only()
async def list_gift_roles(interaction: discord.Interaction) -> None:
    gift_roles = guild_settings(interaction.guild_id)["gift_roles"]
    mentions = [
        role.mention
        for role_id in gift_roles
        if (role := interaction.guild.get_role(int(role_id))) is not None
    ]
    message = "\n".join(mentions) if mentions else "No gift roles are configured."
    await interaction.response.send_message(message, ephemeral=True)


class RewardChanceModal(discord.ui.Modal, title="Set reward chance"):
    percent = discord.ui.TextInput(
        label="Chance percentage (0–100)",
        placeholder="25",
        required=True,
        max_length=8,
    )

    def __init__(self, gift_role_id: int, reward_role_id: int):
        super().__init__()
        self.gift_role_id = gift_role_id
        self.reward_role_id = reward_role_id

    async def on_submit(self, interaction: discord.Interaction) -> None:
        guild = interaction.guild
        if guild is None or not is_admin(interaction):
            await interaction.response.send_message(
                "You need the Manage Roles permission to configure gifts.", ephemeral=True
            )
            return

        data = guild_settings(guild.id)
        gift_role = guild.get_role(self.gift_role_id)
        reward_role = guild.get_role(self.reward_role_id)
        if (
            gift_role is None
            or str(self.gift_role_id) not in {str(role_id) for role_id in data["gift_roles"]}
            or reward_role is None