Skip to main content

Disnake mini library with Dishka integration

Project description

Dishka-Disnake Documentation

Note: Before using dishka-disnake, it is recommended to familiarize yourself with the principles of Dishka, as this library builds on them while providing a Disnake-like interface.

dishka-disnake is a wrapper for Disnake that allows you to use all standard Disnake interactions (slash commands, user commands, message commands, buttons, selects, and modals) with a slightly different import structure and simplified setup.


Installation

pip install dishka-disnake

Setup

To initialize your bot with Dishka, you need to call setup_dishka before creating your bot instance. This ensures that all Dishka integrations are properly configured in the asynchronous container:

from dishka import make_async_container, AsyncContainer
from dishka_disnake import setup_dishka
from disnake.ext.commands import Bot

# Create the async container for your bot
container: AsyncContainer = make_async_container(...)

async def main():
    # Setup Dishka integration on the container before creating the bot
    setup_dishka(container)

    # Now you can create your bot instance
    bot = Bot(...)

    # Start your bot
    await bot.start("YOUR_BOT_TOKEN")

setup_dishka(async_container) prepares your async container so that commands, buttons, selects, and modals work correctly with Dishka.


Commands

dishka-disnake supports all standard Disnake command types(only cogs):


Slash Commands

from dishka_disnake.commands import slash_command

class HelloCog(Cog)

    @slash_command(name="hello", description="Say hello")
    async def hello_command(interaction: AppCmdInter, usecase: FromDishka[HelloUseCase]):
        ...

UserCommands

from dishka_disnake.commands import user_command

class HelloCog(Cog)

    @user_command(name="hello", description="Say hello")
    async def hello_command(interaction: AppCmdInter, usecase: FromDishka[HelloUseCase]):
        ...

MessageCommands

from dishka_disnake.commands import message_command

class HelloCog(Cog)

    @message_command(name="hello", description="Say hello")
    async def hello_command(interaction: AppCmdInter, usecase: FromDishka[HelloUseCase]):
        ...

Components

Buttons

from disnake import ui, MessageInteraction
from dishka_disnake.ui import Button, button


class MyButton(Button):
    def __init__(self):
        super().__init__(label="My Button", style=ButtonStyle.primary)

    async def callback(self, interaction: MessageInteraction, repo: FromDishka[UserRepo]):
        ...


class MyView(ui.View):
    def __init__(self):
        super().__init__()
        self.add_item(MyButton())

    @button(label="My Button")
    async def my_button_callback(self, interaction: MessageInteraction, repo: FromDishka[UserRepo]):
        ...

Selects

from disnake import ui, MessageInteraction, SelectOption
from dishka_disnake.ui import Select, select


class MySelect(Select):
    def __init__(self):
        super().__init__(placeholder="My Select", options=[
            SelectOption(label="Option 1", value="1"),
            SelectOption(label="Option 2", value="2"),
        ])

    async def callback(self, interaction: MessageInteraction, repo: FromDishka[UserRepo]):
        ...


class MyView(ui.View):
    def __init__(self):
        super().__init__()
        self.add_item(MySelect())

    @select(placeholder="My Select")
    async def my_select_callback(self, interaction: MessageInteraction, repo: FromDishka[UserRepo]):
        ...

similar with UserSelect, RoleSelect, MentionableSelect, ChannelSelect and StringSelect

Modals

from disnake import ModalInteraction
from dishka_disnake.ui import Modal, modal


class MyModal(Modal):
    def __init__(self):
        super().__init__(title="My Modal", components=[
            TextInput(label="My Input", style=TextInputStyle.short),
            TextInput(label="My Input Description", style=TextInputStyle.paragraph),
        ])

    async def callback(self, interaction: ModalInteraction, repo: FromDishka[UserRepo]):
        ...

Notes

  • The usage of commands, buttons, selects, and modals is identical to Disnake.
  • The main difference is the import path (from dishka_disnake instead of from disnake).
  • Make sure to call setup_dishka before initializing your bot, passing the asynchronous container to properly configure Dishka integration.

This documentation should provide a solid starting point for using dishka-disnake while keeping all the familiar patterns from Disnake.

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

dishka_disnake-0.1.5.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

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

dishka_disnake-0.1.5-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file dishka_disnake-0.1.5.tar.gz.

File metadata

  • Download URL: dishka_disnake-0.1.5.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dishka_disnake-0.1.5.tar.gz
Algorithm Hash digest
SHA256 194500ee934a73a811161f9e720e4c95c8fbdb0b69e00c999873ca6d7eb00496
MD5 e71505a8307f483167e4c58fc22b444a
BLAKE2b-256 a30e5c49393e3e09fbafc05c3764fe5047a7861bb7b73ad27b24f7ba7df19f02

See more details on using hashes here.

Provenance

The following attestation bundles were made for dishka_disnake-0.1.5.tar.gz:

Publisher: release.yml on NodusPanic/dishka-disnake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dishka_disnake-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: dishka_disnake-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dishka_disnake-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 aa38e660bf766d5698794c69a0b5124e38f92b3d43adfb0fc8e2e485781a3797
MD5 27435b25352e846e7b8e72a1066064cf
BLAKE2b-256 2967eaf2757f6e2beded97fefe074d26828f8646d23bc6e671dd0dab03591448

See more details on using hashes here.

Provenance

The following attestation bundles were made for dishka_disnake-0.1.5-py3-none-any.whl:

Publisher: release.yml on NodusPanic/dishka-disnake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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