Browse Source

chore: update ActionRow and View

pull/10166/head
DA-344 4 months ago
parent
commit
502051af71
  1. 1
      discord/ui/__init__.py
  2. 28
      discord/ui/action_row.py
  3. 5
      discord/ui/view.py

1
discord/ui/__init__.py

@ -23,3 +23,4 @@ from .section import *
from .separator import *
from .text_display import *
from .thumbnail import *
from .action_row import *

28
discord/ui/action_row.py

@ -43,7 +43,7 @@ from typing import (
)
from .item import Item, ItemCallbackType
from .button import Button
from .button import Button, button as _button
from .dynamic import DynamicItem
from .select import select as _select, Select, UserSelect, RoleSelect, ChannelSelect, MentionableSelect
from ..components import ActionRow as ActionRowComponent
@ -281,22 +281,16 @@ class ActionRow(Item[V]):
"""
def decorator(func: ItemCallbackType[V, Button[V]]) -> ItemCallbackType[V, Button[V]]:
if not inspect.iscoroutinefunction(func):
raise TypeError('button function must be a coroutine function')
func.__discord_ui_parent__ = self
func.__discord_ui_modal_type__ = Button
func.__discord_ui_model_kwargs__ = {
'style': style,
'custom_id': custom_id,
'url': None,
'disabled': disabled,
'label': label,
'emoji': emoji,
'row': None,
'sku_id': None,
}
return func
ret = _button(
label=label,
custom_id=custom_id,
disabled=disabled,
style=style,
emoji=emoji,
row=None,
)(func)
ret.__discord_ui_parent__ = self # type: ignore
return ret # type: ignore
return decorator # type: ignore

5
discord/ui/view.py

@ -223,7 +223,7 @@ class BaseView:
parent = getattr(raw, '__discord_ui_parent__', None)
if parent and parent._view is None:
parent._view = self
item = raw
children.append(raw)
else:
item: Item = raw.__discord_ui_model_type__(**raw.__discord_ui_model_kwargs__)
item.callback = _ViewCallback(raw, self, item) # type: ignore
@ -231,9 +231,8 @@ class BaseView:
setattr(self, raw.__name__, item)
parent = getattr(raw, '__discord_ui_parent__', None)
if parent:
if not self._is_v2():
raise RuntimeError('This view cannot have v2 items')
parent._children.append(item)
continue
children.append(item)
return children

Loading…
Cancel
Save