From 911409f133cfe5af63629f8b8f43cec6a000fe94 Mon Sep 17 00:00:00 2001 From: 404kuso Date: Sun, 12 Dec 2021 13:33:00 +0100 Subject: [PATCH] updated doumentation --- discord_ui/receive.py | 3 ++ docs/source/_static/css/main.css | 10 +++++ examples/README.md | 5 ++- examples/calculator.py | 3 +- examples/cogs.py | 66 ++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 examples/cogs.py diff --git a/discord_ui/receive.py b/discord_ui/receive.py index 7507fe5..c24e2e8 100644 --- a/discord_ui/receive.py +++ b/discord_ui/receive.py @@ -43,9 +43,12 @@ 'SubSlashInteraction', 'SlashedSubCommand', # deprecated + 'ContextInteraction', + 'Interaction', ) + class InteractionType: PING = Ping = 1 APPLICATION_COMMAND = Command = 2 diff --git a/docs/source/_static/css/main.css b/docs/source/_static/css/main.css index 7b454dd..ae7ad39 100644 --- a/docs/source/_static/css/main.css +++ b/docs/source/_static/css/main.css @@ -71,19 +71,23 @@ html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not( max-width: 100%; } +/* Buttons */ .btn.btn-neutral { border: 1px solid #2C2F33; border-radius: 5px; color: white } +/* Note box background */ .rst-content .note .admonition-title, .note .admonition-title { background-color: rgba(88,101,242,.5); } +/* Warning box title */ .rst-content .warning .admonition-title, .warning .admonition-title { background-color: #fee65cad; } +/* Warning box background */ .rst-content .warning, .warning { background-color: rgba(254,231,92,.5); } @@ -109,6 +113,11 @@ code.docutils.literal.notranslate, .highlight, div.highlight-default.notranslate color: white; } + +html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.glossary):not(.simple) .descclassname { + color: white; +} + html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.glossary):not(.simple)>dt:first-child { font-family: SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,Courier,monospace; color: white; @@ -123,6 +132,7 @@ html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not( background-color: #5865F2; } +/* Navigationsdings */ .wy-side-nav-search, .wy-nav-top { /* background-color: #5865F2; */ background: #5865F2; diff --git a/examples/README.md b/examples/README.md index 89e5781..134ffc4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -20,4 +20,7 @@ Here is a list of possible examples of how to use our package : Sends a hidden select menu to a user, who can choose between roles which he will get upon selecting - [`staff messager`](https://github.com/discord-py-ui/discord-ui/tree/main/examples/staff_message.py) - : slashcommand with autocomplete for sending messages to a staff mmember \ No newline at end of file + : slashcommand with autocomplete for sending messages to a staff mmember + +- [`cog example`](https://github.com/discord-py-ui/discord-ui/tree/main/examples/cogs.py) + : simple example for using application commands in cogs \ No newline at end of file diff --git a/examples/calculator.py b/examples/calculator.py index 7a56d01..f8deadf 100644 --- a/examples/calculator.py +++ b/examples/calculator.py @@ -9,8 +9,7 @@ import asyncio from discord.ext import commands -from discord_ui import SlashInteraction, UI, Button -from discord_ui.components import LinkButton +from discord_ui import SlashInteraction, UI, Button, LinkButton # The main discord bot client client = commands.Bot(" ") diff --git a/examples/cogs.py b/examples/cogs.py new file mode 100644 index 0000000..26ac25a --- /dev/null +++ b/examples/cogs.py @@ -0,0 +1,66 @@ +# Example by 404kuso +# https://github.com/discord-py-ui/discord-ui/tree/main/examples/cpgs.py +# +# This is just a simple cog command example for application commands +# Note: +# If you want to test this, replace '785567635802816595' in guild_ids=[] with a guild id of +# your choice, because guild slash commands are way faster than globals + +# import discord package +import discord +# import commands extention +from discord.ext import commands +from discord_ui import ( + UI, cogs, SlashOption, + # interaction types for type hinting + SlashInteraction, AutocompleteInteraction, ContextInteraction, + # overridden message object for type hinting + Message +) + +# initialize bot +bot = commands.Bot(" ") + + +# create the cog +class ExampleCog(commands.Cog): + # add slashcommand to cog + @cogs.slash_command("my_command", "this is an example cog command", guild_ids=[785567635802816595]) + # callback for the command + async def my_command(self, ctx: SlashInteraction): + ... + + + # method that generates choices for the 'hello world' command + async def my_generator(self, ctx: AutocompleteInteraction): + return [("hello", "1"), ("world", "2")] + + # add subslash command to the cog + @cogs.subslash_command("hello", "world", "example subcommand", [ + # simple option that uses autocompletion + SlashOption(str, "argument", "option that autogenerates somethning", choice_generator=my_generator) + ]) + # callback for the commmand + async def my_subcommand(self, ctx: SlashInteraction, argument: str): + ... + + + # add message command to cog + @cogs.message_command("message", guild_ids=[785567635802816595]) + # callbackfor the command + async def my_message_command(self, ctx: ContextInteraction, message: Message): + ... + + + # add user command to cog + @cogs.user_command("user", guild_ids=[785567635802816595]) + # callback for the command + async def my_user_command(self, ctx: ContextInteraction, member: discord.Member): + ... + + +# add the cog to the bot +bot.add_cog(ExampleCog()) + +# login +bot.run("your token") \ No newline at end of file