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.
DishkaCog
DishkaCog is a base class for Cogs that automatically injects dependencies from the Dishka container into all supported handlers — no decorators needed.
Supported handler types:
- Slash commands (
@commands.slash_command) - User commands (
@commands.user_command) - Message commands (
@commands.message_command) - Prefix commands (
@commands.command) - Events (
@Cog.listener)
from dishka import FromDishka
from dishka_disnake import DishkaCog
from disnake import AppCmdInter
from disnake.ext import commands
from disnake.ext.commands import Bot, Context
class MyCog(DishkaCog):
def __init__(self, bot: Bot):
self.bot = bot
# Slash command — session is injected automatically
@commands.slash_command(name="hello")
async def hello(self, interaction: AppCmdInter, session: FromDishka[AsyncSession]):
await interaction.response.send_message(f"Hello! {session}")
# Prefix command — session is injected automatically
@commands.command(name="ping")
async def ping(self, ctx: Context, session: FromDishka[AsyncSession]):
await ctx.send(f"Pong! {session}")
# User command — session is injected automatically
@commands.user_command(name="info")
async def info(self, interaction: AppCmdInter, session: FromDishka[AsyncSession]):
await interaction.response.send_message(f"Info! {session}")
# Message command — session is injected automatically
@commands.message_command(name="quote")
async def quote(self, interaction: AppCmdInter, session: FromDishka[AsyncSession]):
await interaction.response.send_message(f"Quote! {session}")
# Listener event — session is injected automatically
@Cog.listener("on_ready")
async def on_ready(self, session: FromDishka[AsyncSession]):
print(f"Ready! {session}")
def setup(bot: Bot):
bot.add_cog(MyCog(bot))
Subcommands and subcommand groups
DishkaCog also works with subcommands and subcommand groups:
class MyCog(DishkaCog):
def __init__(self, bot: Bot):
self.bot = bot
@commands.slash_command()
async def base(self, interaction: AppCmdInter):
pass
@base.sub_command()
async def sub(self, interaction: AppCmdInter, session: FromDishka[AsyncSession]):
await interaction.response.send_message(f"Sub! {session}")
@commands.slash_command()
async def group(self, _: AppCmdInter):
pass
@group.sub_command_group()
async def subgroup(self, _: AppCmdInter):
pass
@subgroup.sub_command()
async def nested(self, interaction: AppCmdInter, session: FromDishka[AsyncSession]):
await interaction.response.send_message(f"Nested! {session}")
Difference from @inject
If you only need injection on specific methods rather than the entire Cog, use the @inject decorator on individual methods in a regular Cog instead of inheriting from DishkaCog:
from dishka_disnake import inject
class MyCog(Cog):
@slash_command(name="hello")
@inject
async def hello(self, interaction: AppCmdInter, session: FromDishka[AsyncSession]):
await interaction.response.send_message(f"Hello! {session}")
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(self, 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(self, 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(self, 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_disnakeinstead offrom disnake). - Make sure to call
setup_dishkabefore initializing your bot, passing the asynchronous container to properly configure Dishka integration. DishkaCogautomatically patches Disnake's parameter validation when imported, so no additional setup is required.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dishka_disnake-0.1.61.tar.gz.
File metadata
- Download URL: dishka_disnake-0.1.61.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b07fc19d46796263f0e4e6f6fd6e8452f1eb9a7a1721f7b20b2408495f05c274
|
|
| MD5 |
955e7f426c3c35a60e529d60c7cb070f
|
|
| BLAKE2b-256 |
95314e169046913c08e9fc6a20ed4248dad204e61628790065f585f7edc8b069
|
Provenance
The following attestation bundles were made for dishka_disnake-0.1.61.tar.gz:
Publisher:
release.yml on NodusPanic/dishka-disnake
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dishka_disnake-0.1.61.tar.gz -
Subject digest:
b07fc19d46796263f0e4e6f6fd6e8452f1eb9a7a1721f7b20b2408495f05c274 - Sigstore transparency entry: 1343714834
- Sigstore integration time:
-
Permalink:
NodusPanic/dishka-disnake@abd25e522818cd31c4b948c5cbad35c025c464ac -
Branch / Tag:
refs/tags/v0.1.61 - Owner: https://github.com/NodusPanic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@abd25e522818cd31c4b948c5cbad35c025c464ac -
Trigger Event:
push
-
Statement type:
File details
Details for the file dishka_disnake-0.1.61-py3-none-any.whl.
File metadata
- Download URL: dishka_disnake-0.1.61-py3-none-any.whl
- Upload date:
- Size: 44.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17a38914ef1b7ee93d92ed6b892fa7d2f851663f616b2568a3745920369bbe99
|
|
| MD5 |
57251bf4c2cb6ddcd9967084c5f619bd
|
|
| BLAKE2b-256 |
620db37b5574ae4e3d0f0cdf1a1dd09870355726932d261f2b9542b2e672f781
|
Provenance
The following attestation bundles were made for dishka_disnake-0.1.61-py3-none-any.whl:
Publisher:
release.yml on NodusPanic/dishka-disnake
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dishka_disnake-0.1.61-py3-none-any.whl -
Subject digest:
17a38914ef1b7ee93d92ed6b892fa7d2f851663f616b2568a3745920369bbe99 - Sigstore transparency entry: 1343714848
- Sigstore integration time:
-
Permalink:
NodusPanic/dishka-disnake@abd25e522818cd31c4b948c5cbad35c025c464ac -
Branch / Tag:
refs/tags/v0.1.61 - Owner: https://github.com/NodusPanic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@abd25e522818cd31c4b948c5cbad35c025c464ac -
Trigger Event:
push
-
Statement type: