Skip to main content

Pycord Reactive Views

Pycord Reactive Views is a powerful library that extends Pycord, bringing reactive programming to Discord bot development. It enables developers to create dynamic, responsive user interfaces for their bots with ease.

Color select example

Table of Contents

What is Reactivity?

Reactivity is a programming paradigm commonly used in front-end development. It allows for the creation of dynamic user interfaces that update in real-time based on changes in the underlying data. Pycord Reactive Views brings this powerful concept to Discord bot development.

In Pycord, reactivity is implemented through View classes. These classes are responsible for:

  • Rendering the user interface
  • Updating the UI in response to data changes
  • Handling user interactions

Features

  • Reactive Components: Create buttons, select menus, and other Discord components that automatically update based on your bot's state.
  • Declarative Syntax: Define your UI logic in a clear, declarative manner.
  • Easy Integration: Seamlessly integrates with existing Pycord projects.
  • Performance Optimized: Efficiently updates only the components that have changed.

Installation

To install Pycord Reactive Views, use pip:

pip install pycord-reactive-views

Ensure you have Pycord installed as well:

pip install py-cord

Quick Start

Here's a simple example of a reactive counter view:

from pycord_reactive_views import ReactiveView, ReactiveButton, ReactiveValue

class Counter(ReactiveView):
    def __init__(self):
        super().__init__()
        self.counter = 0
        self.counter_button = ReactiveButton(
            label=ReactiveValue(lambda: f"Count: {self.counter}", "Count: 0"),
            style=ReactiveValue(
                lambda: discord.ButtonStyle.primary if self.counter % 2 == 0 else discord.ButtonStyle.secondary,
                discord.ButtonStyle.primary,
            ),
        )
        self.reset_button = ReactiveButton(
            label="Reset",
            style=discord.ButtonStyle.danger,
            disabled=ReactiveValue(lambda: self.counter == 0, True),
        )
        self.counter_button.callback = self._increment
        self.reset_button.callback = self._reset
        self.add_item(self.counter_button)
        self.add_item(self.reset_button)

    async def _increment(self, interaction: discord.Interaction) -> None:
        await interaction.response.defer()
        self.counter += 1
        await self.update()

    async def _reset(self, interaction: discord.Interaction) -> None:
        await interaction.response.defer()
        self.counter = 0
        await self.update()

# Usage in your bot
@bot.command()
async def counter(ctx):
    view = Counter()
    await Counter().send(ctx)

Counter Example

This example demonstrates how to bind a button's label, style, and disabled state to functions that determine their values based on the current state of the counter.

Documentation

Comprehensive documentation is coming soon. In the meantime, please refer to the examples in the examples directory and the inline comments in the source code for guidance on using Pycord Reactive Views.

Examples

Check out the examples directory in our GitHub repository for more detailed examples of how to use Pycord Reactive Views in various scenarios.

Contributing

We welcome contributions to Pycord Reactive Views! If you'd like to contribute, please:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Make your changes and write tests if applicable
  4. Submit a pull request with a clear description of your changes

For major changes or feature requests, please open an issue first to discuss what you would like to change.

License

Pycord Reactive Views is licensed under the MIT License. See the LICENSE file for more information.

Metadata

Release files for pycord-reactive-views 1.0.2

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

Source distribution (sdist)

Source distribution for pycord-reactive-views 1.0.2
File Size Uploaded Provenance Actions
pycord_reactive_views-1.0.2.tar.gz 7.4 kB Without provenance Details for pycord_reactive_views-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycord-reactive-views 1.0.2
File Interpreter ABI Platform Actions
pycord_reactive_views-1.0.2-py3-none-any.whl Python 3 none any Details for pycord_reactive_views-1.0.2-py3-none-any.whl

Total release size: 15.1 kB

Release files / pycord_reactive_views-1.0.2.tar.gz

Download URL pycord_reactive_views-1.0.2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2d5c09601260758b41294471856adc7902dbff374979de6e94aae725f96c0400
BLAKE2b-256 checksum
How to use checksums
fdc4bab8eb82a07da70d3fff8aa70dadc1e6e5674f2cb89775def588b66ae3af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.6.5

Release files / pycord_reactive_views-1.0.2-py3-none-any.whl

Download URL pycord_reactive_views-1.0.2-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cf2c5f4f1754ab378fcfc937d2300b0831ab5912c992cf505c1d86029f6cf76
BLAKE2b-256 checksum
How to use checksums
8b89bc7296de0df0c54ff766969ca82793a7be1b054e3a9de08e92836e115b65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.6.5

Security for pycord-reactive-views 1.0.2

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.

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