Add Message.jump_url helper (#68)
Some checks failed
Deploy MkDocs / deploy (push) Has been cancelled

This commit is contained in:
Slipstream 2025-06-11 18:24:20 -06:00 committed by GitHub
parent 7c7bebc95a
commit def2ff0183
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 8 deletions

View File

@ -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

View File

@ -115,6 +115,13 @@ class Message:
# 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:
"""Returns message content without user, role, or channel mentions."""

View File

@ -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