Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit bb77664

Browse files
committed
2 parents b68b77e + 911409f commit bb77664

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

discord_ui/receive.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@
4343
'SubSlashInteraction',
4444
'SlashedSubCommand', # deprecated
4545

46+
'ContextInteraction',
47+
4648
'Interaction',
4749
)
4850

51+
4952
class InteractionType:
5053
PING = Ping = 1
5154
APPLICATION_COMMAND = Command = 2

docs/source/_static/css/main.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,23 @@ html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(
7171
max-width: 100%;
7272
}
7373

74+
/* Buttons */
7475
.btn.btn-neutral {
7576
border: 1px solid #2C2F33;
7677
border-radius: 5px;
7778
color: white
7879
}
7980

81+
/* Note box background */
8082
.rst-content .note .admonition-title, .note .admonition-title {
8183
background-color: rgba(88,101,242,.5);
8284
}
8385

86+
/* Warning box title */
8487
.rst-content .warning .admonition-title, .warning .admonition-title {
8588
background-color: #fee65cad;
8689
}
90+
/* Warning box background */
8791
.rst-content .warning, .warning {
8892
background-color: rgba(254,231,92,.5);
8993
}
@@ -109,6 +113,11 @@ code.docutils.literal.notranslate, .highlight, div.highlight-default.notranslate
109113
color: white;
110114
}
111115

116+
117+
html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.glossary):not(.simple) .descclassname {
118+
color: white;
119+
}
120+
112121
html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.glossary):not(.simple)>dt:first-child {
113122
font-family: SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,Courier,monospace;
114123
color: white;
@@ -123,6 +132,7 @@ html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(
123132
background-color: #5865F2;
124133
}
125134

135+
/* Navigationsdings */
126136
.wy-side-nav-search, .wy-nav-top {
127137
/* background-color: #5865F2; */
128138
background: #5865F2;

examples/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ Here is a list of possible examples of how to use our package
2020
: Sends a hidden select menu to a user, who can choose between roles which he will get upon selecting
2121

2222
- [`staff messager`](https://github.com/discord-py-ui/discord-ui/tree/main/examples/staff_message.py)
23-
: slashcommand with autocomplete for sending messages to a staff mmember
23+
: slashcommand with autocomplete for sending messages to a staff mmember
24+
25+
- [`cog example`](https://github.com/discord-py-ui/discord-ui/tree/main/examples/cogs.py)
26+
: simple example for using application commands in cogs

examples/calculator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
import asyncio
1111
from discord.ext import commands
12-
from discord_ui import SlashInteraction, UI, Button
13-
from discord_ui.components import LinkButton
12+
from discord_ui import SlashInteraction, UI, Button, LinkButton
1413

1514
# The main discord bot client
1615
client = commands.Bot(" ")

examples/cogs.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Example by 404kuso
2+
# https://github.com/discord-py-ui/discord-ui/tree/main/examples/cpgs.py
3+
#
4+
# This is just a simple cog command example for application commands
5+
# Note:
6+
# If you want to test this, replace '785567635802816595' in guild_ids=[] with a guild id of
7+
# your choice, because guild slash commands are way faster than globals
8+
9+
# import discord package
10+
import discord
11+
# import commands extention
12+
from discord.ext import commands
13+
from discord_ui import (
14+
UI, cogs, SlashOption,
15+
# interaction types for type hinting
16+
SlashInteraction, AutocompleteInteraction, ContextInteraction,
17+
# overridden message object for type hinting
18+
Message
19+
)
20+
21+
# initialize bot
22+
bot = commands.Bot(" ")
23+
24+
25+
# create the cog
26+
class ExampleCog(commands.Cog):
27+
# add slashcommand to cog
28+
@cogs.slash_command("my_command", "this is an example cog command", guild_ids=[785567635802816595])
29+
# callback for the command
30+
async def my_command(self, ctx: SlashInteraction):
31+
...
32+
33+
34+
# method that generates choices for the 'hello world' command
35+
async def my_generator(self, ctx: AutocompleteInteraction):
36+
return [("hello", "1"), ("world", "2")]
37+
38+
# add subslash command to the cog
39+
@cogs.subslash_command("hello", "world", "example subcommand", [
40+
# simple option that uses autocompletion
41+
SlashOption(str, "argument", "option that autogenerates somethning", choice_generator=my_generator)
42+
])
43+
# callback for the commmand
44+
async def my_subcommand(self, ctx: SlashInteraction, argument: str):
45+
...
46+
47+
48+
# add message command to cog
49+
@cogs.message_command("message", guild_ids=[785567635802816595])
50+
# callbackfor the command
51+
async def my_message_command(self, ctx: ContextInteraction, message: Message):
52+
...
53+
54+
55+
# add user command to cog
56+
@cogs.user_command("user", guild_ids=[785567635802816595])
57+
# callback for the command
58+
async def my_user_command(self, ctx: ContextInteraction, member: discord.Member):
59+
...
60+
61+
62+
# add the cog to the bot
63+
bot.add_cog(ExampleCog())
64+
65+
# login
66+
bot.run("your token")

0 commit comments

Comments
 (0)