Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

starlight-dpy

A utility library that she uses for discord.py

This 'library' is still in pre-alpha. This is still actively being develop and major changes may be made :3

Feel free to open an issue if you found any bugs!🌷

Do not use this in production.

Installation

Requires discord.py 2.7.1 or newer.

pip install starlight-dpy==0.0.1b8

Or install the latest commit from GitHub:

pip install git+https://github.com/InterStella0/starlight-dpy

To pin a release tag from GitHub instead:

pip install git+https://github.com/InterStella0/starlight-dpy@v0.0.1b8

Help Command

Menu Help Command

Easily paginate your help command with little effort.
import starlight
import discord

from discord.ext import commands

bot = commands.Bot(
    command_prefix="??",
    help_command=starlight.MenuHelpCommand(
        per_page=10,
        accent_color=0xffcccb,
        error_color=discord.Color.red()
    ),
    intents=discord.Intents.all(),
    description="Demonstration bot"
)

Output

default.png

Customizing

You can easily customize your help command by overriding format_* methods!

Format methods:

  • format_command_brief(cmd: commands.Command)
  • format_cog_page(view: HelpMenuCog, data: List[commands.Command])
  • format_bot_page(view: HelpMenuBot, mapping: Dict[Optional[commands.Cog], List[commands.Command]])
  • format_group_detail(view: HelpMenuGroup)
  • format_command_detail(view: HelpMenuCommand)
  • format_error_detail(view: HelpMenuError)

Note:page suffix meant the View inherits SimplePaginationView

Example:

import starlight
import discord

from discord.ext import commands

class MyMenuHelpCommand(starlight.MenuHelpCommand):
    async def format_bot_page(self, view, mapping):
        return discord.Embed(
            title="Help",
            description="Choose a category to display your help command!",
            color=self.accent_color
        )


bot = commands.Bot(
    command_prefix="??",
    help_command=MyMenuHelpCommand(
            per_page=10,
            accent_color=0xffcccb,
            error_color=discord.Color.red(),
            pagination_buttons={
                "start_button": discord.ui.Button(emoji="⏪", row=1),
                "previous_button": discord.ui.Button(emoji="◀️", style=discord.ButtonStyle.blurple, row=1),
                "stop_button": discord.ui.Button(emoji="⏹️", style=discord.ButtonStyle.red, row=1),
                "next_button": discord.ui.Button(emoji="▶️", style=discord.ButtonStyle.blurple, row=1),
                "end_button": discord.ui.Button(emoji="⏩", row=1)
            }
    ),
    intents=discord.Intents.all(),
    description="Demonstration bot"
)

Output

output.png

Paginate Help Command

Uses buttons for navigation.
import starlight
import discord

from discord.ext import commands

bot = commands.Bot(
    command_prefix="??",
    help_command=starlight.PaginateHelpCommand(),
    intents=discord.Intents.all()
)

Output

output.png

Help Hybrid Command

Hybrid is a term to implement both text and slash command in discord.py.

Injection

HelpCommand was explicitly only a text command. For existing HelpCommand implementation, you can change it to a hybrid, you can use starlight.convert_help_hybrid.

import starlight
from discord.ext import commands

my_help_command = commands.DefaultHelpCommand()
hybrid_help_command = starlight.convert_help_hybrid(my_help_command)
bot = commands.Bot(..., help_command=hybrid_help_command)

Once you sync your command. You can now use help command in slash command.

Note: convert_help_hybrid second argument is directly transfered to the AppCommand parameters.

Inherits

For new implementation of helpcommand, you can directly inherits starlight.HelpHybridCommand. This will have several helpful feature to integrate with app command. with_app_command should also be set to True

import starlight
from discord.ext import commands

class MyHelp(starlight.HelpHybridCommand):
    async def send_bot_help(self, mapping, /) -> None:
        no_command = len([c for cog in mapping.values() for c in cog])
        response = f'I have `{no_command:,}` commands!'
        await self.get_destination().send(response)

bot = commands.Bot(..., help_command=MyHelp(with_app_command=True))

Once you sync your command. You can now use help command in slash command.

Output

output.png

Views

Inline View

A shortcut for view handling. Create inline view for distinct behaviours with `starlight.inline_view`.
import starlight
import discord

@bot.command()
async def my_command(ctx):
    view = discord.ui.View()
    hi_button = discord.ui.Button(label="hi")
    view.add_item(hi_button)
    await ctx.send("hi", view=view)
    async for interaction, item in starlight.inline_view(view):
        if item is hi_button:
            response = "hi"
        else:
            response = "unknown"
        await interaction.response.send_message(response, ephemeral=True)

You can specify a discord.ui.Item to listen for a single item. Effective when you're expecting only a single interaction.

result = None
async for interaction, item in starlight.inline_view(view, item=hi_button):
    result = await view.get_my_result(interaction)
    view.stop()  # ensure only a single sequence

print("My Result:", result)

Note:

  • Interaction callbacks are sequential due to async iterator.
  • Always go for View subclasses whenever you can.

Pagination View

A simple pagination interface.

This was designed to not rely on discord.ext.menus due to lack of support for Interaction. Majority of code that was present in discord.ext.menus was dedicated for Reaction which has made it not ideal to be inherited.

import starlight
import discord

class MyPagination(starlight.SimplePaginationView):
    async def format_page(self, interaction, data):
        return discord.Embed(
            title=f"Simple display[{self.current_page + 1}/{self.max_pages}]",
            description="\n".join(data)
        )


@bot.command()
async def my_command(ctx):
    my_data = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]]
    view = MyPagination(my_data, cache_page=True)
    await view.start(ctx)

Note: You're required to chunk your data on your own. Tips:discord.utils.as_chunks

Supports commands.Paginator with .from_paginator classmethod.

Output

output.png

Inline Pagination

Paginating can have distinct formats which could cause boilerplate code. Which leads to the creation of Inline Pagination. It works similarly with Inline View. With a slight change, `InlinePaginationItem` are yielded for you to respond it to have an effect to the message through `.format()` method.
import starlight
import discord

@bot.command()
async def my_command(ctx):
    my_data = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]]
    view = starlight.SimplePaginationView(my_data, cache_page=True)
    async for item in starlight.inline_pagination(view, context=ctx):
        embed = discord.Embed(
            title=f"Simple display[{view.current_page + 1}/{view.max_pages}]",
            description="\n".join(item.data)
        )
        item.format(embed=embed)  # keyword arguments are passed to `Message.edit`

The output of this code is the equivalent of the Pagination View example.

General Utility

An extended version of discord.utils.get(). However, it is a filter that returns a sequence. This also supports for fuzzy matching as they are relatively common to be used within a discord bot.
from starlight import search, Contains
# Contains is alias of ContainsFilter class
items_with_my_value = search(items, my_attr=Contains('my_value'))

# Equivalent of
items_contains_value = [item for item in items if 'my_value' in item.my_attr]

Flatten

Flatten nested iterables.
from starlight import flatten

arr = [[1, 2], [3, [4, 5], 6], 7, [8]]
arr_flatten = flatten(arr)
print(arr_flatten)  # -> [1, 2, 3, 4, 5, 6, 7, 8]

Converters

Separator

Greedy behaviour with a separator instead of spaces as delimiter. By default, this is set to ',' as the delimiter. It can be configured by passing 'separator' keyword argument.
from starlight import star_commands

@star_commands.command(bot=bot) # this is required for separators
async def my_command(ctx, colours: star_commands.Separator[discord.Color], *, the_rest: str):
    await ctx.send(f"{colours} | '{the_rest}'")

Output

output.png

References

Contributors

contributors

Metadata

Release files for starlight-dpy 0.0.1b8

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

Source distribution (sdist)

Source distribution for starlight-dpy 0.0.1b8
File Size Uploaded Provenance Actions
starlight_dpy-0.0.1b8.tar.gz 39.9 kB Without provenance Details for starlight_dpy-0.0.1b8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for starlight-dpy 0.0.1b8
File Interpreter ABI Platform Actions
starlight_dpy-0.0.1b8-py3-none-any.whl Python 3 none any Details for starlight_dpy-0.0.1b8-py3-none-any.whl

Total release size: 81.3 kB

Release files / starlight_dpy-0.0.1b8.tar.gz

Download URL starlight_dpy-0.0.1b8.tar.gz
Size 39.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a94349ad46e832dc07187d34ea05c84b64b688182ac38ef72ae129a9f87ea1c3
BLAKE2b-256 checksum
How to use checksums
cfc36b2540159a86d70746ca878c4a0c6af7f50e80d5727f53683cc3ef3e1fc7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.8

Release files / starlight_dpy-0.0.1b8-py3-none-any.whl

Download URL starlight_dpy-0.0.1b8-py3-none-any.whl
Size 41.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8088898a6d074aeaea41892c641ad4aa48e4864fc5e13fd316c1c88b46460d5d
BLAKE2b-256 checksum
How to use checksums
ac0203842464a33902ca8e094d3d12c6b889433754bbddec014628623ef4f156
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.8

Security for starlight-dpy 0.0.1b8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
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