Skip to main content

discord.py UI

An extension package for anything relating to user input and interactions.

Ever wanted to make a prompt for your users? Maybe a cool paginator? dpy-ui will make it all happen in simple, easy to remember functions and classes.

Installation

Requires Python 3.6+

pip install -U dpy-ui

Development version

pip install -U git+https://github.com/Ikusaba-san/discord.py-ui.git

or

git clone git+https://github.com/Ikusaba-san/discord.py-ui.git
cd discord.py-ui
pip install -U .[voice]

Then once it's installed, you can import it via

from discord.ext import ui

Quick Examples

Prompt the user for some input

name = await ui.prompt(ctx, 'What is your name?')
await ctx.send(f'Ok, your name is {name}')

Choose between a list of choices

choices = ['red', 'blue', 'green', 'yellow']
colour = await ui.select(ctx, 'What is your favo(u)rite colo(u)r?', choices)

# Want buttons instead of text? No problem.

choices = [
    ui.Choice('Very Happy', button='😄'),
    ui.Choice('Happy', button='🙂'),
    ui.Choice('Neutral', button='😐'),
    ui.Choice('Sad', button='😦'),
    ui.Choice('Very Sad', button='😢'),
]
feeling = await ui.select(ctx, 'How are you feeling today?', choices)

Make a simple paginator

def some_statements():
    for i in range(20):
        yield f'This is sentence {i}'

def format_page(page):
    return f'This is a page\n{page}'

paginator = ui.Paginator(some_statements(), page_formatter=format_page)
await paginator.start(ctx)

# And to chunk it:

def format_chunk(chunk):
    # Formatters can return embeds too
    return discord.Embed(description='\n'.join(chunk))

paginator = ui.Paginator.chunked(some_statements(), 10, page_formatter=format_chunk)
await paginator.start(ctx)

Make a custom session

class MySession(ui.Session):
    async def send_initial_message(self):
        return await self.context.send('Say hi or click the thinking face.')

    @ui.button('🤔')
    async def think(self, payload):
        await self.context.send('Thinking a lot...')

    @ui.button('⏹')
    async def quit(self, payload):
        await self.stop()

    @ui.command('hello|hi')
    async def say_hello(self, message):
        await self.context.send(f'Hello, {message.author.mention}!')

session = MySession(timeout=120)
await session.start(ctx)

Metadata

Release files for dpy-ui 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dpy-ui 0.2.1
File Size Uploaded
dpy-ui-0.2.1.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dpy-ui 0.2.1
File Interpreter ABI Platform
dpy_ui-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 22.9 kB

Release files / dpy-ui-0.2.1.tar.gz

Download URL dpy-ui-0.2.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
396a01c463341cd47c694ad5d393486480a0cbeb8a9375af6f43f3a401e4689d
BLAKE2b-256 checksum
How to use checksums
07dd06f39f08379ae0e3b855065ea968d0fea35d3af8d735d671797b3b239a55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release files / dpy_ui-0.2.1-py3-none-any.whl

Download URL dpy_ui-0.2.1-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14c9a0ff1f9314107a1d7b3bef29f5b3b7324c74ef7540323b9e37ba075b8403
BLAKE2b-256 checksum
How to use checksums
7da83eb443891c8322c496b642b746e78cfca164ac8fa2fedded6cc8300181f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page