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 - Gateway and HTTP API clients
- Slash command framework - Slash command framework
- Message component helpers - Message component helpers
- `Message.jump_url` property for quick links to messages
- Built-in caching layer - Built-in caching layer
- Experimental voice support - Experimental voice support
- Helpful error handling utilities - Helpful error handling utilities

View File

@ -106,14 +106,21 @@ class Message:
] ]
else: else:
self.components = None self.components = None
self.attachments: List[Attachment] = [ self.attachments: List[Attachment] = [
Attachment(a) for a in data.get("attachments", []) Attachment(a) for a in data.get("attachments", [])
] ]
self.pinned: bool = data.get("pinned", False) self.pinned: bool = data.get("pinned", False)
# Add other fields as needed, e.g., attachments, embeds, reactions, etc. # Add other fields as needed, e.g., attachments, embeds, reactions, etc.
# self.mentions: List[User] = [User(u) for u in data.get("mentions", [])] # self.mentions: List[User] = [User(u) for u in data.get("mentions", [])]
# self.mention_roles: List[str] = data.get("mention_roles", []) # self.mention_roles: List[str] = data.get("mention_roles", [])
# self.mention_everyone: bool = data.get("mention_everyone", False) # 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 @property
def clean_content(self) -> str: def clean_content(self) -> str:

View File

@ -8,6 +8,9 @@ async for message in channel.history(limit=200):
print(message.content) 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. 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 ## Next Steps