File tree Expand file tree Collapse file tree 3 files changed +26
-12
lines changed Expand file tree Collapse file tree 3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 1
- Add ` make_link() ` function to ` MessageReference ` class.
1
+ - Add ` message_link ` property to ` MessageReference `
2
+ - Add ` channel_link ` property to ` MessageReference `
Original file line number Diff line number Diff line change @@ -309,17 +309,27 @@ class MessageReference:
309
309
a guild.
310
310
"""
311
311
312
- def make_link (self ) -> str :
313
- """Generate a jump link to the referenced message or channel (in case for follow add messages).
312
+ @property
313
+ def message_link (self ) -> typing .Optional [str ]:
314
+ """Generate a jump link to the referenced message.
314
315
315
- Returns
316
- -------
317
- str
318
- The jump link to the message reference target.
316
+ This will be [`None`][] for channel follow add messages. This may
317
+ point to a deleted message.
318
+ """
319
+ if self .id is None :
320
+ return None
321
+
322
+ guild_id_str = "@me" if self .guild_id is None else self .guild_id
323
+ return f"{ urls .BASE_URL } /channels/{ guild_id_str } /{ self .channel_id } /{ self .id } "
324
+
325
+ @property
326
+ def channel_link (self ) -> str :
327
+ """Generate a jump link to the channel the referenced message was sent in.
328
+
329
+ This will always be a valid link.
319
330
"""
320
331
guild_id_str = "@me" if self .guild_id is None else self .guild_id
321
- message_id_str = "" if self .id is None else f"/{ self .id } "
322
- return f"{ urls .BASE_URL } /channels/{ guild_id_str } /{ self .channel_id } { message_id_str } "
332
+ return f"{ urls .BASE_URL } /channels/{ guild_id_str } /{ self .channel_id } "
323
333
324
334
325
335
@attrs_extensions .with_copy
Original file line number Diff line number Diff line change @@ -143,15 +143,18 @@ def message_reference():
143
143
144
144
class TestMessageReference :
145
145
def test_make_link_when_guild_is_not_none (self , message_reference ):
146
- assert message_reference .make_link () == "https://discord.com/channels/123/456/789"
146
+ assert message_reference .message_link == "https://discord.com/channels/123/456/789"
147
+ assert message_reference .channel_link == "https://discord.com/channels/123/456"
147
148
148
149
def test_make_link_when_guild_is_none (self , message_reference ):
149
150
message_reference .guild_id = None
150
- assert message_reference .make_link () == "https://discord.com/channels/@me/456/789"
151
+ assert message_reference .message_link == "https://discord.com/channels/@me/456/789"
152
+ assert message_reference .channel_link == "https://discord.com/channels/@me/456"
151
153
152
154
def test_make_link_when_id_is_none (self , message_reference ):
153
155
message_reference .id = None
154
- assert message_reference .make_link () == "https://discord.com/channels/123/456"
156
+ assert message_reference .message_link is None
157
+ assert message_reference .channel_link == "https://discord.com/channels/123/456"
155
158
156
159
157
160
@pytest .mark .asyncio
You can’t perform that action at this time.
0 commit comments