Skip to main content

Components V2 helper for Discord bots

Project description

UICord

Python Documentation

A UI helper library for pycord that makes Discord's Components V2 simple to work with.

[!CAUTION] This project is a work in progress. Contributions are very welcome!


Features

  • Clean wrappers around every Components V2 primitive (Button, Select, Container, Section, MediaGallery, …)
  • View and Modal subclasses with built-in owner-checking and auto-reload
  • @interaction decorator with automatic error reporting to developers
  • UIString - a str subclass with pluggable i18n via state.translator_function
  • lang= keyword on View and Modal for per-instance translations
  • Graceful pycord 2.7 / 2.8 compatibility shims (MediaGalleryItem, Checkbox, CheckboxGroup)

Installation

pip install uicord

Requires pycord ≥ 2.7.

For Checkbox / CheckboxGroup support, use pycord ≥ 2.8.


Quick Start

import discord
from discord.ext import commands
import uicord

bot = commands.Bot(command_prefix="!")

@bot.slash_command()
async def demo(ctx):
    view = uicord.View(owner=ctx.author.id)
    btn  = uicord.Button("Click me!", color=uicord.Colors.Blue)
    view.add(btn)

    @uicord.interaction(component=btn)
    async def on_click(ictx):
        await ictx.respond("You clicked it!", ephemeral=True)

    await ctx.respond("Here you go:", view=view)

bot.run("TOKEN")

Internationalisation / Localisation

from uicord import state, UIString, View

# Plug in any translation backend
state.translator_function = lambda text, lang: my_i18n(text, lang)

# Translate at construction time
greeting = UIString("hello.world", lang="fr")

# Or let the View handle it - view._("key") returns a UIString in view.lang
view = View(lang="ja")
label = view._("btn.confirm")   # → translated to Japanese

Components at a Glance

Class Description
View Main component container with owner-check and reload
Modal Input/output modal with label helpers
Button Interactable button
Toggle Stateful on/off button
RadioButtons Radio-button group
RadioButtonOption Option inside "Radio buttons" component
Choices Select / drop-down menu
ActionRow Manual row layout
Container Component container
Section Section block (pycord ≥ 2.7)
Separator Visual divider
Thumbnail Inline thumbnail
MediaGallery Media gallery block (pycord ≥ 2.7)
MediaGalleryItem Item inside a MediaGallery (pycord ≥ 2.7)
Text Text display
Checkbox Single checkbox (pycord ≥ 2.8)
CheckboxGroup Group of checkboxes (pycord ≥ 2.8)
UIString Translatable string subclass

Full API reference → uicord.readthedocs.io


Contributing

This project genuinely needs contributors. Bug reports, feature requests, and pull requests are all appreciated.


Originally made for you and the community by H1387Lmao ♥ - open-source, no license. Please keep it that way.

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

uicord-5.0.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

uicord-5.0.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file uicord-5.0.0.tar.gz.

File metadata

  • Download URL: uicord-5.0.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.12.1.2 requests/2.32.5 setuptools/81.0.0 requests-toolbelt/1.0.0 tqdm/4.67.3 CPython/3.13.12

File hashes

Hashes for uicord-5.0.0.tar.gz
Algorithm Hash digest
SHA256 160932246245fd077ad07e4440c4af39fbc44a34c5e9fdf20c05a940f6283c59
MD5 6bd4d723f36f88b357a93797ef8c67fb
BLAKE2b-256 c9f599d8a7cbde1294df880d64e64e6d5a980b10b7a871e70ace74760f94a4c6

See more details on using hashes here.

File details

Details for the file uicord-5.0.0-py3-none-any.whl.

File metadata

  • Download URL: uicord-5.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.12.1.2 requests/2.32.5 setuptools/81.0.0 requests-toolbelt/1.0.0 tqdm/4.67.3 CPython/3.13.12

File hashes

Hashes for uicord-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44c4a4c56250f03043f26c372c8618a077affb8a94f279b2bdaf25d0fb1b70a8
MD5 7d8955efd3cb6554f80eea5ae3594aca
BLAKE2b-256 e83e8233dc7bd83bea9ae2721c5b0af80f8a630482fc37740441e8e3b798053e

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