-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: implement interaction wrapping example
- Loading branch information
1 parent
4baa7df
commit f8d5249
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""A simple example on the use of interaction wrappers.""" | ||
|
||
import os | ||
import typing | ||
|
||
import disnake | ||
from disnake.ext import commands, components | ||
|
||
bot = commands.InteractionBot() | ||
|
||
manager = components.get_manager() | ||
manager.add_to_bot(bot) | ||
|
||
|
||
@manager.register | ||
class MyButton(components.RichButton): | ||
label: typing.Optional[str] = "\N{PROHIBITED SIGN} 클릭" | ||
style: disnake.ButtonStyle = disnake.ButtonStyle.red | ||
|
||
async def callback(self, interaction: components.MessageInteraction) -> None: | ||
await interaction.response.send_message("Don't touch me!") | ||
|
||
|
||
@bot.slash_command() # pyright: ignore # still some unknowns in disnake | ||
@components.wrap_interaction_for | ||
async def with_wrapped_callback(interaction: components.CommandInteraction): | ||
print(MyButton().label) | ||
|
||
return await interaction.response.send_message(components=MyButton()) | ||
|
||
|
||
@bot.slash_command() # pyright: ignore # still some unknowns in disnake | ||
async def with_manual_wrap(interaction: disnake.CommandInteraction): | ||
wrapped = components.wrap_interaction(interaction) | ||
return await wrapped.response.send_message(components=MyButton()) | ||
|
||
|
||
@bot.slash_command() # pyright: ignore # still some unknowns in disnake | ||
async def without_wrap(interaction: disnake.CommandInteraction): | ||
return await interaction.response.send_message( | ||
components=await MyButton().as_ui_component() | ||
) | ||
|
||
|
||
bot.run(os.getenv("EXAMPLE_TOKEN")) |