Skip to content

Commit b51983d

Browse files
committed
fix!: Fix @client.event invocation and choice iteration if not given.
1 parent 76218e3 commit b51983d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

interactions/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ def event(self, coro: Coroutine, name: Optional[str] = MISSING) -> Callable[...,
278278
279279
:param coro: The coroutine of the event.
280280
:type coro: Coroutine
281-
:param name(?): The name of the event.
281+
:param name(?): The name of the event. If not given, this defaults to the coroutine's name.
282282
:type name: Optional[str]
283283
:return: A callable response.
284284
:rtype: Callable[..., Any]
285285
"""
286-
self._websocket.dispatch.register(coro, name)
286+
self._websocket.dispatch.register(coro, name if name is not MISSING else coro.__name__)
287287
return coro
288288

289289
def command(

interactions/models/command.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ def __init__(self, **kwargs) -> None:
114114
self._json["options"] = [
115115
option if isinstance(option, dict) else option._json for option in self.options
116116
]
117-
if all(isinstance(choice, dict) for choice in self.choices):
118-
if isinstance(self._json.get("choices"), dict):
119-
self._json["choices"] = list(self.choices)
120-
else:
121-
self._json["choices"] = [
122-
choice if isinstance(choice, dict) else choice._json for choice in self.choices
123-
]
117+
if self.choices:
118+
if all(isinstance(choice, dict) for choice in self.choices):
119+
if isinstance(self._json.get("choices"), dict):
120+
self._json["choices"] = list(self.choices)
121+
else:
122+
self._json["choices"] = [
123+
choice if isinstance(choice, dict) else choice._json
124+
for choice in self.choices
125+
]
124126

125127

126128
class Permission(DictSerializerMixin):

0 commit comments

Comments
 (0)