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

Commit 6f8cd99

Browse files
committed
merge v5.1 into main
1 parent f281a97 commit 6f8cd99

34 files changed

+3847
-2243
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,5 @@ dmypy.json
133133
.vs/
134134

135135
internal/
136-
test*.py
136+
test*.py
137+
discord_ui/ext.py

README.md

Lines changed: 156 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/discord-ui)
1818
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/550953d11c8242b9b7944642a2e292c7)](https://app.codacy.com/gh/discord-py-ui/discord-ui?utm_source=github.com&utm_medium=referral&utm_content=discord-py-ui/discord-ui&utm_campaign=Badge_Grade_Settings)
1919

20+
2021
## Introduction
2122

2223

2324
This is a [discord.py](https://github.com/Rapptz/discord.py) ui extension made by [404kuso](https://github.com/404kuso) and [RedstoneZockt](https://github.com/RedstoneZockt)
24-
for using discord's newest ui features like buttons, slash commands and context commands (we got dpy2 supported if you want to keep using our libary)
25+
for using discord's newest ui features like buttons, slash commands and context commands.
2526

2627
[Documentation](https://discord-ui.readthedocs.io/en/latest/)
2728

@@ -96,9 +97,9 @@ Example for autocompletion of choices
9697

9798
```py
9899
import discord
99-
from discord_ui import UI, SlashOption, ChoiceGeneratorContext
100+
from discord_ui import UI, SlashOption, AutocompleteInteraction
100101

101-
async def generator(ctx: ChoiceGeneratorContext):
102+
async def generator(ctx: AutocompleteInteraction):
102103
available_choices = ["hmm", "this", "is", "a", "an", "test", "testing"]
103104
return [(x, x) for x in available_choices if x.startswith(ctx.value_query)]
104105

@@ -125,8 +126,8 @@ ui = UI(client)
125126
async def on_message(message: discord.Message):
126127
if message.content == "!btn":
127128
msg = await message.channel.send("you", components=[
128-
[Button("custom_id", "press me", color="green"), LinkButton("https://discord.com", emoji="😁")],
129-
Button("my_custom_id")
129+
[Button("press me", color="green"), LinkButton("https://discord.com", emoji="😁")],
130+
Button(custom_id="my_custom_id")
130131
])
131132
try:
132133
btn = await msg.wait_for("button", client, by=message.author, timeout=20)
@@ -152,10 +153,10 @@ ui = UI(client)
152153
@client.listen("on_message")
153154
async def on_message(message: discord.Message):
154155
if message.content == "!sel":
155-
msg = await message.channel.send("you", components=[SelectMenu("custom_id", options=[
156+
msg = await message.channel.send("you", components=[SelectMenu(options=[
156157
SelectOption("my_value", label="test", description="this is a test"),
157158
SelectOption("my_other_value", emoji="🤗", description="this is a test too")
158-
], max_values=2)])
159+
], "custom_id", max_values=2)])
159160
try:
160161
sel = await msg.wait_for("select", client, by=message.author, timeout=20)
161162
await sel.respond("you selected `" + str([x.content for x in sel.selected_options]) + "`")
@@ -169,7 +170,7 @@ Example for cogs
169170
```py
170171
from discord.ext import commands
171172
from discord_ui import UI
172-
from discord_ui.cogs import slash_cog, subslash_cog, listening_component_cog
173+
from discord_ui.cogs import slash_command, subslash_command, listening_component
173174

174175
bot = commands.Bot(" ")
175176
ui = UI(bot)
@@ -178,11 +179,11 @@ class Example(commands.Cog):
178179
def __init__(self, bot):
179180
self.bot = bot
180181

181-
@slash_cog(name="example", guild_ids=[785567635802816595])
182+
@slash_command(name="example", guild_ids=[785567635802816595])
182183
async def example(self, ctx):
183184
await ctx.respond("gotchu")
184185

185-
@subslash_cog(base_names="example", name="command"):
186+
@subslash_command(base_names="example", name="command"):
186187
async def example_command(self, ctx):
187188
await ctx.respond("okayy")
188189

@@ -193,13 +194,151 @@ bot.run("your token")
193194
You can find more (and better) examples [here](https://github.com/discord-py-ui/discord-ui/tree/main/examples)
194195

195196

197+
198+
## Contact
199+
200+
You can contact us on discord
201+
202+
- [**Redstone**](https://discord.com/users/355333222596476930)
203+
- [**kuso**](https://discord.com/users/539459006847254542)
204+
- [**discord server**](https://discord.gg/bDJCGD994p)
205+
206+
196207
# Changelog
197208

198209
- <details>
199-
<summary>5.0.2</summary>
210+
<summary>5.1.0</summary>
211+
212+
## **Breaking changes**
213+
- Component custom ids are now optional, if no custom id is passed, a 100 characters long random string will be used and because of that the order of Component init params changed
214+
- The order of SelectMenus init params changed, `custom_id` comes now after `options`
215+
```py
216+
SelectMenu("my_custom_id", [options...here])
217+
# is now
218+
SelectMenu([options...here], "my_custom_id")
219+
```
220+
- Same for Buttons
221+
```py
222+
Button("my_custom_id", "label")
223+
# is now
224+
Button("label", "my_custom_id")
225+
```
226+
- ButtonStyles is now ButtonStyle
227+
- renamed cog decorators, the old ones still work but they will show a deprecation warning: `slash_command` -> `slash_command`, `subslash_command` -> `subslash_command`, `context_cog` -> `context_command`, `listening_component` -> `listening_component`
228+
- Removed `Slash.edit_command` and `Slash.edit_subcommand`, "moved" to `Command.edit`
229+
- `SlashedCommand` is now `SlashInteraction`, `SlashedSubCommand` is now `SubSlashInteraction` and `SlashedContext` is now `ContextInteraction`
230+
- The command attributes of CommandInteractions (SlashedCommand, ...) are now moved to `Interaction.command.` (the `.command` attribute is a reference to the real command, if you change properties of the command they will be updated)
231+
- The component attributes of an interaction are now moved to `.component`
232+
- ContextCommands `.param` attribute is now `.target`
233+
234+
## **Changed**
235+
- `argument_type` in SlashOption is now `type`
236+
- `ButtonStyle` value names changed: color names are now capitalized and `Danger` is now `Destructive`
237+
- `Listener.target_user` is now `Listener.target_users` and can take users, members and ids as the value
238+
- `BaseCommand.options` and `SlashOption.options` is now of type `SlashOptionCollection`, which allows you to acces options by index and name
239+
```py
240+
my_command.options["option name"]
241+
# or
242+
my_command.options[0]
243+
```
244+
You can also use some methods like `.get`, `.set` (which will return itself after it set something, so `SlashOption.set(key, value).set(key, value)` would work) and ``SlashOption.options + SlashOption.option`` will add both SlashOptions together
245+
- If an invalid guild id was passed to a slashcommand, no exception will be raised anymore, it will just be printed into the console and ignored `logging.error()`
246+
- Moved the `discord_ui.ext.py` module into a folder
247+
- `on_button_press` and `on_menu_select` is now `on_button` and `on_select`. The old event names will still work but will be removed in the next release
200248

201249
## **Fixed**
202-
- removed print statements
250+
- disable_action_row
251+
- `ActionRow.disable`
252+
- no interaction events being dispatched because subclasses of dpy2 `commands.Bot` instances wouldn't get overriden which lead to not enabling needed debug events
253+
- when no matching component listener in `Listener` could be found, the events for components events wouldn't be dispatched
254+
- `delete_after` keyword in message send override not working
255+
- mentionable type in slashoptions not being parsed to objects
256+
- `@discord.ext.commands.Cooldown` not working on cog slashcommands
257+
258+
## **Added**
259+
- `**fields` to all functions that edit the message components (like `.disable_components`, `.disable_component`, ...). The `**fields` parameter can be used to edit other properties of the message without using `.edit` again and send a "useless" request
260+
- `@Lister.on_error` and `@Listener.wrong_user` decorators for handling Exceptions in Listeners
261+
- When no keyword was passed to `@Listener.button` or `@Listener.select`, the function will be called on every button/slect
262+
- `channel_type` to SlashOption, list of `discord.ChannelType`. This will restrict the shown channels for channel slash options to this list.
263+
- support for nextcord. Other libs **should** work too, but they are not tested.
264+
- `Mentionable` type for SlashOptions
265+
- description for short slashoptions. If you set the options for a slash command via callback params, you can add a description (and a type) to them with your docstring. There are 3 different styles you can use:
266+
```py
267+
# style 1
268+
@ui.slash.command()
269+
async def my_command(ctx, my_option, my_other_option):
270+
"""This is my command description
271+
272+
my_option: `int`:
273+
This is the description for the my_option parameter
274+
my_other_option: `str`:
275+
This is the description for another option
276+
"""
277+
...
278+
279+
# style 2
280+
@ui.slash.command()
281+
async def my_command(ctx, my_option: int, my_other_option: str):
282+
"""This is my command description
283+
284+
my_option: This is the description for the my_option parameter
285+
my_other_option: This is the description for another option
286+
"""
287+
...
288+
289+
# style 3
290+
@ui.slash.command()
291+
async def my_command(ctx, my_option, my_other_option: str):
292+
"""This is my command description
293+
294+
295+
`int`: This is the description for the my_option parameter
296+
297+
This is the description for another option
298+
"""
299+
...
300+
```
301+
Note: You don't have to use `` `type` ``, you can just use `type`
302+
- Empty descriptions for slashcommands and slashoptions. The default description value is now `\u200b` which is an "empty" char
303+
- Modifying slashcommand options is now WWAAYYYY easier. You can just do `.options[name or index].name = "new name"` and the option will be updated
304+
- You can set the autocomplete choice generator with a decorator now
305+
```py
306+
ui.slash.command(options=[SlashOption(str, "my_option")])
307+
async def my_command(ctx, my_option):
308+
...
309+
310+
311+
@my_command.options["my_option"].autocomplete_function
312+
async def my_generator(ctx):
313+
...
314+
# or
315+
@my_command.options[0].autocomplete_function
316+
async def my_generator(ctx):
317+
...
318+
```
319+
- All apllication command decorators will now return the created Command
320+
```py
321+
@ui.slash.command(...)
322+
async my_command(ctx):
323+
...
324+
type(my_command) # SlashCommand
325+
```
326+
- Added edit and delete method to slashcommand. You can use this for editing or deleting the command later
327+
```py
328+
# edit
329+
await my_command.edit(name="test")
330+
# delete
331+
await my_command.delete()
332+
```
333+
- `id` to SlashCommand
334+
- `commands_synced` event which will be dispatched when all commands where synced with the api (`UI.Slash.sync_commands`)
335+
- `BaseCommmand.update` method which updates the api command with the lcoal changes
336+
- `SlashSubCommand.base`, which will be shared among all subslashcommands with the same base
337+
338+
339+
## **Removed**
340+
- `discord.ext.commands.Bot` override for enabling the debug event, this will be enabled when creating a UI instance from the bot
341+
203342
</details>
204343

205344
- <details>
@@ -323,7 +462,7 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
323462
324463
## **Added**
325464
- `discord_ui.ext`
326-
> A module with usefull tools and decorators to use [more information](https://discord-ui.readthedocs.io/en/latest/ext.html)
465+
> A module with useful tools and decorators to use [more information](https://discord-ui.readthedocs.io/en/latest/ext.html)
327466
328467
- BaseCommand
329468
> BaseCommand (the superclass for all applicationcommands) has now some extra properties:
@@ -352,8 +491,8 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
352491
> [more information](https://discord-ui.readthedocs.io/en/latest/listeners.html)
353492
354493
## **Changed**
355-
- SelectedMenu
356-
> `SelectedMenu.selected_values` are not the raw values that were selected, `SelectMenu.selected_options` are the options of type `SlashOption` that were selected
494+
- SelectInteraction
495+
> `SelectInteraction.selected_values` are not the raw values that were selected, `SelectMenu.selected_options` are the options of type `SlashOption` that were selected
357496
- MISSING => None
358497
> All instance values that were `MISSING` by default are now `None`
359498
@@ -632,7 +771,7 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
632771
> You can add and remove listening components now with the `Components.add_listening_component`, `Components.remove_listening_component` and `Components.remove_listening_components` functions
633772

634773
- Cogs
635-
> You can now use cog decorators like `slash_cog`, `subslash_cog` and `listening_component_cog`
774+
> You can now use cog decorators like `slash_command`, `subslash_command` and `listening_component`
636775

637776
## **Fixed**
638777

@@ -863,7 +1002,7 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
8631002

8641003
## **Changed**
8651004

866-
- SelectedMenu
1005+
- SelectInteraction
8671006
> `.values` is not `.selected_values`
8681007

8691008
## **Added**
@@ -1123,12 +1262,3 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
11231262
> Buttons have now a custom hash property, generated by the discord api
11241263

11251264
</details>
1126-
1127-
1128-
## Contact
1129-
1130-
You can contact us on discord
1131-
1132-
- `RedstoneZockt#0001`
1133-
- `! kuso#6969`
1134-
- [discord](https://discord.gg/bDJCGD994p)

discord_ui/__init__.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
discord-ui extension
33
~~~~~~~~~~~~~~~~~~~~
44
5-
A discord.py extension for discord's ui features like Buttons, SelectMenus, LinkButtons slash-commands and context-commands (message-commands and user-commands)
5+
A discord.py extension for discord's ui features like Buttons, SelectMenus, LinkButtons,
6+
slash-commands and context-commands (message-commands and user-commands).
67
7-
This libary features sending components, creating application-commands and receiving them
88
99
- - -
1010
1111
Links
12-
[Docs](https://discord-ui.rtfd.io/) | [Github](https://github.com/discord-py-ui/discord-ui/) | [PyPi](https://pypi.org/project/discord-ui/) | [License](https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt)
12+
[**Docs**](https://discord-ui.rtfd.io/) | [**Github**](https://github.com/discord-py-ui/discord-ui/) | [**PyPi**](https://pypi.org/project/discord-ui/) | [**License**](https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt)
1313
1414
- Made by [404kuso](https://github.com/404kuso) and [RedstoneZockt](https://github.com/RedstoneZockt)
1515
- Made for [discord.py](https://github.com/Rapptz/discord.py) and you
@@ -31,22 +31,21 @@
3131
"""
3232

3333

34-
from .client import Components, Slash, UI
35-
from .components import ActionRow, Button, LinkButton, SelectMenu, SelectOption, ButtonStyles
36-
from .slash.types import OptionType, SlashPermission, SlashOption
37-
from .slash.tools import ParseMethod
38-
from .tools import components_to_dict
39-
from .slash.tools import create_choice
40-
from .receive import Interaction, InteractionType, Message, WebhookMessage, PressedButton, SelectedMenu, ComponentContext, SlashedCommand, SlashedSubCommand, EphemeralMessage, EphemeralResponseMessage, ChoiceGeneratorContext
34+
from .client import *
35+
from .components import *
36+
from .slash.types import *
37+
from .slash.tools import *
38+
from .tools import *
39+
from .slash.tools import *
40+
from .receive import *
41+
from .listener import *
4142
from .slash import ext
42-
from .listener import Listener
43+
from .enums import ButtonStyle, OptionType, Channel, Mentionable
4344

44-
from .override import override_dpy, override_dpy2_client
45-
override_dpy2_client()
4645

46+
from .override import override_dpy
4747

48-
__title__ = "discord-ui"
49-
__version__ = "5.0.2"
5048

51-
if __version__.endswith("a"):
52-
print("Warning: This version is a preview version and can contain some issues!")
49+
__title__ = "discord-ui"
50+
__version__ = "5.1.0"
51+
__author__ = "404kuso, RedstoneZockt"

0 commit comments

Comments
 (0)