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 AsyncContainer
from dishka_disnake import setup_dishka
from disnake.ext.commands import Bot

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

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(inter: AppCmdInter, usecase: FromDishka[HelloUseCase]):  # or HelloUseCase(without 'FromDishka')
        ...

UserCommands

from dishka_disnake.commands import user_command

class HelloCog(Cog)

    @user_command(name="hello", description="Say hello")
    async def hello_command(inter: AppCmdInter, usecase: FromDishka[HelloUseCase]):  # or HelloUseCase(without 'FromDishka')
        ...

MessageCommands

from dishka_disnake.commands import message_command

class HelloCog(Cog)

    @message_command(name="hello", description="Say hello")
    async def hello_command(inter: AppCmdInter, usecase: FromDishka[HelloUseCase]):  # or HelloUseCase(without 'FromDishka')
        ...

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, inter: MessageInteraction, repo: UserRepo):  # or FromDishka[UserRepo]
        ...


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

    @button(label="My Button")
    async def my_button_callback(self, inter: MessageInteraction, repo: UserRepo):  # or 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, inter: MessageInteraction, repo: UserRepo):  # or FromDishka[UserRepo]
        ...


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

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

similar with UserSelect, RoleSelect, MentionableSelect, ChannelSelect and StringSelect

Modals

from disnake import ui, 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, inter: ModalInteraction, repo: UserRepo):  # or 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.3.tar.gz (27.0 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.3-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dishka_disnake-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2b4e0407b4b4e2dffe8246195c63cf619d9700a97970cdb9d402ec50f94c274c
MD5 d27c563d68b7677ccbb209bc5acb4c50
BLAKE2b-256 eac01d2ff77b2d327711ec5a065628537f8b7f57fdf85eee553e3dfb2689f034

See more details on using hashes here.

Provenance

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

Publisher: release.yml on kipoha/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.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for dishka_disnake-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 35f132407149689fcc67ad619a661e254286d106e92d0eee4d6cc3705963c692
MD5 b4edc01c11c40c6c9d58ee8fc0063722
BLAKE2b-256 949e2c69ed2b0300adca193ddce820bf2b2b1d269b35cc14e85664a50602e59c

See more details on using hashes here.

Provenance

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

Publisher: release.yml on kipoha/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