Skip to content

Commit c270804

Browse files
authored
fix!: Message.mention_users can return users if not in guild (#1535)
1 parent de72911 commit c270804

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

interactions/models/discord/message.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,47 @@
88
AsyncGenerator,
99
Dict,
1010
List,
11+
Mapping,
1112
Optional,
1213
Sequence,
1314
Union,
14-
Mapping,
1515
)
1616

1717
import attrs
1818

1919
import interactions.models as models
2020
from interactions.client.const import GUILD_WELCOME_MESSAGES, MISSING, Absent
21-
from interactions.client.errors import ThreadOutsideOfGuild, NotFound
21+
from interactions.client.errors import NotFound, ThreadOutsideOfGuild
2222
from interactions.client.mixins.serialization import DictSerializationMixin
2323
from interactions.client.utils.attr_converters import optional as optional_c
2424
from interactions.client.utils.attr_converters import timestamp_converter
2525
from interactions.client.utils.serializer import dict_filter_none
2626
from interactions.client.utils.text_utils import mentions
2727
from interactions.models.discord.channel import BaseChannel, GuildChannel
28+
from interactions.models.discord.embed import process_embeds
2829
from interactions.models.discord.emoji import process_emoji_req_format
2930
from interactions.models.discord.file import UPLOADABLE_TYPE
30-
from interactions.models.discord.embed import process_embeds
31+
3132
from .base import DiscordObject
3233
from .enums import (
34+
AutoArchiveDuration,
3335
ChannelType,
3436
InteractionType,
3537
MentionType,
3638
MessageActivityType,
3739
MessageFlags,
3840
MessageType,
39-
AutoArchiveDuration,
4041
)
41-
from .snowflake import to_snowflake, Snowflake_Type, to_snowflake_list, to_optional_snowflake
42+
from .snowflake import (
43+
Snowflake_Type,
44+
to_optional_snowflake,
45+
to_snowflake,
46+
to_snowflake_list,
47+
)
4248

4349
if TYPE_CHECKING:
44-
from interactions.client import Client
4550
from interactions import InteractionContext
51+
from interactions.client import Client
4652

4753
__all__ = (
4854
"Attachment",
@@ -365,10 +371,13 @@ class Message(BaseMessage):
365371
_referenced_message_id: Optional["Snowflake_Type"] = attrs.field(repr=False, default=None)
366372

367373
@property
368-
async def mention_users(self) -> AsyncGenerator["models.Member", None]:
374+
async def mention_users(self) -> AsyncGenerator[Union["models.Member", "models.User"], None]:
369375
"""A generator of users mentioned in this message"""
370376
for u_id in self._mention_ids:
371-
yield await self._client.cache.fetch_member(self._guild_id, u_id)
377+
if self._guild_id:
378+
yield await self._client.cache.fetch_member(self._guild_id, u_id)
379+
else:
380+
yield await self._client.cache.fetch_user(u_id)
372381

373382
@property
374383
async def mention_roles(self) -> AsyncGenerator["models.Role", None]:

0 commit comments

Comments
 (0)