An Declarative UI Kit for discord.py
Project description
This package is extension of discord.ui.
You can build ui like SwiftUI.
Features
View System
You can build UI by View class.
View.body function returns what you want to show.
Combine System
You can use Combine like Swift’s Combine.
Example
from discord.ext.ui import Component, Button, View, ObservedObject, Published, Message
from discord.ext import commands
import discord
import os
client = commands.Bot("!")
class SampleViewModel(ObservedObject):
def __init__(self):
super().__init__()
self.num = Published(0)
def countup(self):
self.num += 1
def countdown(self):
self.num -= 1
class SampleView(View):
def __init__(self):
super().__init__()
self.viewModel = SampleViewModel()
async def add_reaction(self):
await self.discord_message.add_reaction("\U0001f44d")
async def body(self):
return Message(
content=f"test! {self.viewModel.num}",
component=Component(items=[
[
Button("+1")
.on_click(lambda x: self.viewModel.countup())
.style(discord.ButtonStyle.blurple),
Button("-1")
.on_click(lambda x: self.viewModel.countdown())
.style(discord.ButtonStyle.blurple)
]
])
)
@client.event
async def on_message(message):
if message.content != "!test":
return
await SampleView().start(client, message.channel)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
discord-ext-ui-1.0.1.tar.gz
(7.3 kB
view hashes)
Built Distribution
Close
Hashes for discord_ext_ui-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aa940c94aabd0701fadc75959811769f37bd2e9dfe3c806907849e2fff04100 |
|
MD5 | 64ded6f39a494a59448ccd15264fc8f1 |
|
BLAKE2b-256 | deea6b9ce281761ac7db15f558efc2ad28295268ed58db14694e048d64711d30 |