_hypex1_

Make me a discord bot anout roleplay with economy /roleplay start przypomnij and zakoncz and just best you can for roleplay bot

Kodari AI
KodariSep 30 at 5:33 pm 1
RoleplayEconomyBot
A Discord roleplay bot with an integrated economy system. Players can start, manage, and end roleplay sessions using commands like /roleplay start, /roleplay przypomnij (remind), and /roleplay zakoncz (end). The bot tracks player characters, manages in-game currency, enables item trading, and maintains persistent character inventories. Features include session timers with automatic reminders, character creation and progression, shop systems for purchasing items, and a comprehensive economy ledger tracking all transactions. The bot uses SQLite for data persistence and provides rich embed responses for all interactions.
  1. Utworzę bota discord.py ze slash-komendami RP po polsku.

  2. Dodam ekonomię, nagrody za udział i trwały zapis sesji oraz sald w SQLite.

  3. Przygotuję pliki zależności, przykładowe .env i instrukcję uruchomienia.

Gotowy bot RP po polsku: sesje mają komendy /roleplay start, /roleplay dolacz, /roleplay przypomnij i /roleplay zakoncz. Uczestnicy dostają 50 monet po zakończeniu sesji; ekonomia zawiera saldo, startowe 100 monet i codzienną nagrodę 100 monet. Sesje i salda są zapisywane w SQLite.

Utworzyłem bot.py, database.py, requirements.txt, .env.example i README.md. Skopiuj .env.example do .env, wpisz token bota, zainstaluj zależności i uruchom python bot.py.

_hypex1_

where do i put token bot

Kodari AI
KodariSep 30 at 5:34 pm 1

Create a .env file in the same folder as bot.py and add:

Env
DISCORD_TOKEN=your_bot_token_here

Replace your_bot_token_here with your token from the Discord Developer Portal. Don’t share or commit the token.

_hypex1_

i put one and still no working

Kodari AI
KodariSep 30 at 5:38 pm 1

I updated bot.py to load .env from the same folder as the script, even if you launch it from another folder.

Check that you have a file named .env (not .env.example or .env.txt) next to bot.py, containing:

Env
DISCORD_TOKEN=paste_your_bot_token_here

Use the bot token from Discord Developer Portal → your application → Bot. Then run python bot.py and check the terminal. If it still doesn’t start, paste the exact error message here—but remove any token or secret first.

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

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

from database import Database

load_dotenv(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".env"))

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
logger = logging.getLogger("roleplay_bot")

STARTING_BALANCE = 100
DAILY_REWARD = 100
ROLEPLAY_REWARD = 50


class RoleplayBot(commands.Bot):
    def __init__(self) -> None:
        super().__init__(command_prefix="!", intents=discord.Intents.default())
        self.database = Database(os.getenv("DATABASE_PATH", "roleplay.sqlite3"))

    async def setup_hook(self) -> None:
        await self.database.initialize()
        synced = await self.tree.sync()
        logger.info("Zsynchronizowano %s komend aplikacji.", len(synced))

    async def close(self) -> None:
        await self.database.close()
        await super().close()


bot = RoleplayBot()
roleplay = app_commands.Group(name="roleplay", description="Prowadzenie sesji roleplay")
economy = app_commands.Group(name="ekonomia", description="Twoje monety i nagrody")
bot.tree.add_command(roleplay)
bot.tree.add_command(economy)


async def guild_id_for(interaction: discord.Interaction) -> int | None:
    if interaction.guild_id is None:
        await interaction.response.send_message(
            "Tej komendy można używać tylko na serwerze.", ephemeral=True
        )
        return None
    return interaction.guild_id


@roleplay.command(name="start", description="Rozpocznij nową sesję roleplay na tym kanale")
async def roleplay_start(interaction: discord.Interaction, tytul: str) -> None:
    guild_id = await guild_id_for(interaction)
    if guild_id is None:
        return

    title = tytul.strip()
    if not title:
        await interaction.response.send_message("Podaj tytuł sesji.", ephemeral=True)
        return

    session = await bot.database.start_session(
        guild_id, interaction.channel_id, interaction.user.id, title
    )
    if session is None:
        await interaction.response.send_message(
            "Na tym kanale trwa już sesja. Użyj `/roleplay przypomnij` albo `/roleplay zakoncz`.",
            ephemeral=True,
        )
        return

    embed = discord.Embed(
        title=f"🎭 {title}",
        description=(
            f"Sesja rozpoczęta przez {interaction.user.mention}.\n"
            "Dołącz komendą `/roleplay dolacz`. Każdy uczestnik otrzyma **"
            f"{ROLEPLAY_REWARD} monet** po zakończeniu sesji."
        ),
        color=discord.Color.purple(),
    )
    embed.timestamp = discord.utils.utcnow()
    await interaction.response.send_message(embed=embed)


@roleplay.command(name="dolacz", description="Dołącz do sesji roleplay na tym kanale")
async def roleplay_join(interaction: discord.Interaction) -> None:
    guild_id = await guild_id_for(interaction)
    if guild_id is None:
        return

    joined = await bot.database.join_session(
        guild_id, interaction.channel_id, interaction.user.id
    )
    if joined is None:
        await interaction.response.send_message(
            "Na tym kanale nie ma aktywnej sesji roleplay.", ephemeral=True
        )
    elif joined:
        await interaction.response.send_message(
            f"{interaction.user.mention} dołącza do sesji! Po jej zakończeniu otrzymasz "
            f"**{ROLEPLAY_REWARD} monet**."
        )
    else:
        await interaction.response.send_message(
            "Już jesteś uczestnikiem tej sesji.", ephemeral=True
        )


@roleplay.command(name="przypomnij", description="Przypomnij o trwającej sesji roleplay")
async def roleplay_remind(interaction: discord.Interaction) -> None:
    guild_id = await guild_id_for(interaction)
    if guild_id is None:
        return

    session = await bot.database.get_session(guild_id, interaction.channel_id)
    if session is None:
        await interaction.response.send_message(
            "Na tym kanale nie ma aktywnej sesji roleplay.", ephemeral=True
        )
        return

    embed = discord.Embed(
        title="🔔 Przypomnienie o roleplay",
        description=(
            f"Trwa sesja **{discord.utils.escape_markdown(session['title'])}**. "
            "Dołącz komendą `/roleplay dolacz` i baw się dobrze!"
        ),
        color=discord.Color.gold(),
    )
    embed.set_footer(text=f"Sesję prowadzi: {session['starter_name']}")
    await interaction.response.send_message(embed=embed)


@roleplay.command(name="zakoncz", description="Zakończ sesję i wypłać nagrody uczestnikom")
async def roleplay_end(interaction: discord.Interaction) -> None:
    guild_id = await guild_id_for(interaction)
    if guild_id is None:
        return

    session = await bot.database.get_session(guild_id, interaction.channel_id)
    if session is None:
        await interaction.response.send_message(
            "Na tym kanale nie ma aktywnej sesji roleplay.", ephemeral=True
        )
        return
    if interaction.user.id != session["starter_id"] and not interaction.user.guild_permissions.manage_messages:
        await interaction.response.send_message(
            "Sesję może zakończyć jej prowadzący lub moderator z uprawnieniem zarządzania wiadomościami.",
            ephemeral=True,
        )
        return

    result = await bot.database.finish_session(
        guild_id, interaction.channel_id, ROLEPLAY_REWARD
    )
    if result is None:
        await interaction.response.send_message(
            "Ta sesja została już zakończona.", ephemeral=True
        )
        return

    embed = discord.Embed(
        title="🏁 Sesja zakończona",
        description=(
            f"**{discord.utils.escape_markdown(result['title'])}** dobiegła końca.\n"
            f"Uczestnicy: **{len(result['participants'])}** · Nagroda: **"
            f"{ROLEPLAY_REWARD} monet na osobę**."
        ),
        color=discord.Color.green(),
    )
    await interaction.response.send_message(embed=embed)


@economy.command(name="saldo", description="Sprawdź swoje saldo lub saldo innej osoby")
async def economy_balance(
    interaction: discord.Interaction, osoba: discord.Member | None = None
) -> None:
    guild_id = await guild_id_for(interaction)
    if guild_id is None:
        return

    target = osoba or interaction.user
    balance = await bot.database.get_balance(
        guild_id, target.id, STARTING_BALANCE
    )
    await interaction.response.send_message(
        f"💰 **{target.display_name}** ma **{balance} monet**.", ephemeral=True
    )


@economy.command(name="dziennie", description="Odbierz codzienną nagrodę")
async def economy_daily(interaction: discord.Interaction) -> None:
    guild_id = await guild_id_for(interaction)
    if guild_id is None:
        return