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

Commit e4727b0

Browse files
author
kuso-senpai
committed
fixed dm interactions
1 parent 6837dc2 commit e4727b0

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
158158

159159
# Changelog
160160

161+
- <details>
162+
<summary>3.3.0</summary>
163+
164+
## **Fixed**
165+
- interaction usage in dms
166+
167+
</details>
168+
161169
- <details>
162170
<summary>3.2.9</summary>
163171
## **Added**

discord_ui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
from .override import override_dpy
99
override_dpy()
1010

11-
__version__ = "3.2.9"
11+
__version__ = "3.3.0"

discord_ui/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ async def _on_response(self, msg):
138138
if int(data["type"]) not in [1, 2]:
139139
return
140140

141-
guild = cache_data(data["guild_id"], AdditionalType.GUILD, data, self._discord._connection)
142-
user = discord.Member(data=data["member"], guild=guild, state=self._discord._connection)
141+
guild = None
142+
if data.get("guild_id") is not None:
143+
guild = cache_data(data["guild_id"], AdditionalType.GUILD, data, self._discord._connection)
144+
user = discord.Member(data=data["member"], guild=guild, state=self._discord._connection) if data.get("member") is not None else discord.User(state=self._discord._connection, data=data["user"])
143145
channel = await handle_thing(data["channel_id"], OptionType.CHANNEL, data, self.parse_method, self._discord)
144146

145147
interaction = Interaction(self._discord._connection, data, user)
@@ -856,8 +858,10 @@ async def _on_response(self, msg):
856858
if data["type"] != 3:
857859
return
858860

859-
guild = cache_data(data["guild_id"], AdditionalType.GUILD, data, self._discord._connection)
860-
user = discord.Member(data=data["member"], guild=guild, state=self._discord._connection)
861+
guild = None
862+
if data.get("guild_id") is not None:
863+
guild = cache_data(data["guild_id"], AdditionalType.GUILD, data, self._discord._connection)
864+
user = discord.Member(data=data["member"], guild=guild, state=self._discord._connection) if data.get("member") is not None else discord.User(state=self._discord._connection, data=data["user"])
861865
msg = await getResponseMessage(self._discord._connection, data=data, user=user, response=True)
862866

863867
interaction = Interaction(self._discord._connection, data, user, msg)

discord_ui/receive.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,27 @@ def __init__(self, state, data, user=MISSING, message=None) -> None:
2929
self._responded: bool = False
3030

3131
if user is not MISSING:
32-
self.member = user
32+
self.member: typing.Union[discord.Member, discord.User] = user
3333
"""The user who created the interaction
3434
35-
:type: :class:`discord.Member`
35+
:type: :class:`discord.Member` | :class:`discord.User`
3636
"""
37-
38-
self._original_payload = data
39-
self.application_id = data["application_id"]
40-
self.token = data["token"]
37+
self._original_payload: dict = data
38+
self.application_id: int = data["application_id"]
39+
self.token: str = data["token"]
4140
"""The token for responding to the interaction"""
42-
self.id = data["id"]
41+
self.id: int = data["id"]
4342
"""The id of the interaction"""
44-
self.type = data["type"]
43+
self.type: int = data["type"]
4544
"""The type of the interaction. See :class:`~InteractionType` for more information"""
46-
self.version = data["version"]
47-
self.data = data["data"]
45+
self.version: int = data["version"]
46+
self.data: dict = data["data"]
4847
"""The passed data of the interaction"""
49-
self.channel_id = data["channel_id"]
48+
self.channel_id: int = data.get("channel_id")
5049
"""The channel-id where the interaction was created"""
51-
self.guild_id = data["guild_id"]
50+
self.guild_id: int = data.get("guild_id")
5251
"""The guild-id where the interaction was created"""
53-
self.message = message
52+
self.message: Message = message
5453
"""The message of the interaction"""
5554

5655
async def defer(self, hidden=False):

0 commit comments

Comments
 (0)