Skip to main content

Discord bot wrapper dengan syntax sederhana dan powerful

Project description

Image

License: MIT Python version SQLite PyPI Discord

[Click here to see the PyPi page]

SulvionPiCord (SPC) is a simple and powerful Python wrapper for discord.py. It is designed to minimize boilerplates and make Discord bot development more intuitive, especially for beginners and rapid prototyping.

✨ Features

  • Simplified Decorators: Register text commands, slash commands, and button callbacks with ease.
  • Integrated Database: Built-in SQLite wrapper for easy data persistence.
  • Unified Context: A single Context object that works across messages, interactions, and buttons.
  • Micro-Framework Style: Inspired by modern web frameworks like Flask/FastAPI for bot events.
  • Hybrid Support: Easily handle both asynchronous and synchronous command logic.
  • Premium Error Handling: Automated, user-friendly error messages that stay out of your terminal.

🚀 Installation

  • Easy, just type pip install sulvion-picord
  • And import it using from spc import *

🛠️ Quick Start

Creating a bot is as simple as this:

import spc

# Initialize Bot
bot = spc.initBot(prefix="!")

# Initialize optional database
bot.initDB("my_bot.db")

@bot.onRecv("ping")
async def ping(ctx):
    """A simple ping command."""
    await ctx.reply("Pong! 🏓")

@bot.onSlash("hello", description="Says hello!")
async def hello_slash(ctx):
    await ctx.reply(f"Hello {ctx.sender.name}!", hidden=True)

@bot.onButton("click_me")
async def on_button(ctx):
    await ctx.reply("System: Button Clicked!")

# Run the bot
bot.run("YOUR_BOT_TOKEN")

📦 Key Components

🤖 Bot

The core bot object, initialized with spc.initBot(). It handles command registration and event loop management.

📝 Context

A powerful unified object passed to your commands. It gives you easy access to:

  • ctx.sender: The user who triggered the command.
  • ctx.reply(): Smart replies (text, ephemeral, or interaction-based).
  • ctx.db: Direct access to the integrated database.

🗄️ Database

A built-in SQLite wrapper.

# Create a table
ctx.db.create_table("users", {"id": "INTEGER PRIMARY KEY", "score": "INTEGER"})

# Upsert data
ctx.db.upsert("users", {"id": ctx.sender.id, "score": 100})

📚 API Reference

Bot

  • spc.initBot(prefix="~", ...): Initialize the SPC Bot instance.
  • bot.initDB(path: str): Connect/Create an integrated SQLite database.
  • bot.onRecv(name: str, *props): Decorator for text commands. Use spc.NOPREFIX in props for prefixless commands.
  • bot.onSlash(name: str, description: str): Decorator for slash commands.
  • bot.onButton(custom_id: str): Decorator for button callbacks.
  • bot.run(token: str): Starts the bot and connects to Discord.

Context (ctx)

  • ctx.reply(msg=None, embed=None, components=None, hidden=False, delete_after=None): Intelligent reply (supports Slash, Buttons, and Text).
  • ctx.send(msg=None, ...): Sends a message to the current channel.
  • ctx.dm(msg=None, ...): Sends a direct message to the user who triggered the command.
  • ctx.react(emoji): Adds a reaction to the command message.
  • ctx.sleep(seconds: float): Asynchronous sleep utility.
  • ctx.time(): Returns the current UNIX timestamp.
  • ctx.rand(min: int, max: int): Returns a random integer between min and max.
  • ctx.sender: A Sender object containing id, name, mention, and avatar_url.

Database

  • db.get(query, params=(), one=False): Fetch data from the database.
  • db.execute(query, params=()): Execute a raw SQL query.
  • db.create_table(name, schema): Create a table using a dictionary {col: type} or raw string.
  • db.upsert(table, data: dict): Simple "Insert or Replace" operation.
  • db.update(table, where: dict, set_vals: dict): Update rows based on conditions.
  • db.delete(table, where: dict): Delete rows based on conditions.

📄 License

Distributed under the MIT License. See LICENSE for more information.

👤 Author

Hafiz Daffa W.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sulvion_picord-0.1.4.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sulvion_picord-0.1.4-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file sulvion_picord-0.1.4.tar.gz.

File metadata

  • Download URL: sulvion_picord-0.1.4.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for sulvion_picord-0.1.4.tar.gz
Algorithm Hash digest
SHA256 0d564e944216081c7736db758b70ad9bff34bc8964d57d2c35d002f6012df9bb
MD5 aa211c792d09429d79af9860273afbdd
BLAKE2b-256 898c838afbe6e9bdf2f9dd2db511f26f9e35e8046f58c582a797636eff71d343

See more details on using hashes here.

File details

Details for the file sulvion_picord-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: sulvion_picord-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for sulvion_picord-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 384c4707922c872e0a04e7adfe8733d1d2d32e620822efc4c242a2661e7fea38
MD5 f4cdda5d6be139e949e2861438aaa177
BLAKE2b-256 43501858bf870c211cdcd9ee88c4b40fc000eaa66f9a8f9ccb36be98c75be930

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page