diff --git a/README.md b/README.md index 1519149..d3805f8 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A Python library for interacting with the Discord API, with a focus on bot devel - Gateway and HTTP API clients - Slash command framework - Message component helpers +- `Message.jump_url` property for quick links to messages - Built-in caching layer - Experimental voice support - Helpful error handling utilities diff --git a/disagreement/models.py b/disagreement/models.py index 0fd0391..1bbe2ef 100644 --- a/disagreement/models.py +++ b/disagreement/models.py @@ -106,14 +106,21 @@ class Message: ] else: self.components = None - self.attachments: List[Attachment] = [ - Attachment(a) for a in data.get("attachments", []) - ] - self.pinned: bool = data.get("pinned", False) - # Add other fields as needed, e.g., attachments, embeds, reactions, etc. - # self.mentions: List[User] = [User(u) for u in data.get("mentions", [])] - # self.mention_roles: List[str] = data.get("mention_roles", []) - # self.mention_everyone: bool = data.get("mention_everyone", False) + self.attachments: List[Attachment] = [ + Attachment(a) for a in data.get("attachments", []) + ] + self.pinned: bool = data.get("pinned", False) + # Add other fields as needed, e.g., attachments, embeds, reactions, etc. + # self.mentions: List[User] = [User(u) for u in data.get("mentions", [])] + # self.mention_roles: List[str] = data.get("mention_roles", []) + # self.mention_everyone: bool = data.get("mention_everyone", False) + + @property + def jump_url(self) -> str: + """Return a URL that jumps to this message in the Discord client.""" + + guild_or_dm = self.guild_id or "@me" + return f"https://discord.com/channels/{guild_or_dm}/{self.channel_id}/{self.id}" @property def clean_content(self) -> str: diff --git a/docs/message_history.md b/docs/message_history.md index 0d26969..b183b02 100644 --- a/docs/message_history.md +++ b/docs/message_history.md @@ -8,6 +8,9 @@ async for message in channel.history(limit=200): print(message.content) ``` +Each returned `Message` has a ``jump_url`` property that links directly to the +message in the Discord client. + Pass `before` or `after` to control the range of messages returned. The paginator fetches messages in batches of up to 100 until the limit is reached or Discord returns no more messages. ## Next Steps