Skip to main content

An extension for disnake aimed at making component interactions with listeners somewhat less cumbersome.

Project description

NOTE

disnake-compass

An extension for disnake aimed at making component interactions with listeners somewhat less cumbersome.
Requires disnake version 2.10.0 or above and python 3.10.0 or above.

Key Features

  • Smoothly integrates with disnake,
  • Uses an intuitive dataclass-like syntax to create innately persistent components,
  • custom_id matching, conversion, and creation are automated for you.

Installing

Python 3.10 or higher and disnake 2.10.0 or higher are required

To install the extension, run the following command in your command prompt/shell:

# Linux/macOS
python3 -m pip install -U disnake-compass

# Windows
py -3 -m pip install -U disnake-compass

It can then be imported as

import disnake_compass

Examples

A very simple component that increments its label each time you click it can be written as follows:

import disnake
from disnake.ext import commands
import disnake_compass


bot = commands.InteractionBot()
manager = disnake_compass.get_manager()
manager.add_to_client(bot)


@manager.register
class MyButton(disnake_compass.RichButton):
    count: int

    async def callback(self, interaction: disnake.MessageInteraction[disnake.Client]) -> None:
        self.count += 1
        self.label = str(self.count)

        await interaction.response.edit_message(components=self)


@bot.slash_command()
async def test_button(interaction: disnake.CommandInteraction[disnake.Client]) -> None:
    component = await MyButton(label="0", count=0).as_ui_component()

    await interaction.send(components=component)


bot.run("TOKEN")

For extra examples, please see the examples folder.

To-Do

  • Implement modals,
  • Improve Cog support by somehow injecting the cog instance,
  • Contribution guidelines,

Contributing

Any contributions are welcome, feel free to open an issue or submit a pull request if you would like to see something added. Contribution guidelines will come soon.

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

disnake_compass-1.0.1.tar.gz (43.5 kB view details)

Uploaded Source

Built Distribution

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

disnake_compass-1.0.1-py3-none-any.whl (58.0 kB view details)

Uploaded Python 3

File details

Details for the file disnake_compass-1.0.1.tar.gz.

File metadata

  • Download URL: disnake_compass-1.0.1.tar.gz
  • Upload date:
  • Size: 43.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.9

File hashes

Hashes for disnake_compass-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4128289918716f9b8f873122e015c57a6ec995dc9129a1776060ab17f3e8e18a
MD5 0ce3be5b3c10417e969a68096eb256e5
BLAKE2b-256 6bc50253f1c5896f00dcba99d473e79fca14e636b2f036e7ebfe2cd619cb4602

See more details on using hashes here.

File details

Details for the file disnake_compass-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for disnake_compass-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 20c2270ead0214fc208a62bfaf585b7d2d0014fdc5c538455eb6f99567554db9
MD5 e9641f5623840dab270dca9e206aeabf
BLAKE2b-256 b3b31c60849e838fc22515ce30cb3c822b879a57cbb3daa6151d7b2139cce8d5

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