aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-03-25 09:08:22 -0400
committerRapptz <[email protected]>2021-03-25 09:08:22 -0400
commit5cb512654819bbb90d45f3fcd721b2b17cb5d30e (patch)
treec2b436dafde3ae9b2dfd86841d61595252efab55
parentImplicitly cast Embed construction parameters to str (diff)
downloaddiscord.py-5cb512654819bbb90d45f3fcd721b2b17cb5d30e.tar.xz
discord.py-5cb512654819bbb90d45f3fcd721b2b17cb5d30e.zip
Make Attachment hashable and castable to str
-rw-r--r--discord/message.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/discord/message.py b/discord/message.py
index a34ba711..c681d33e 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -68,9 +68,30 @@ def convert_emoji_reaction(emoji):
raise InvalidArgument('emoji argument must be str, Emoji, or Reaction not {.__class__.__name__}.'.format(emoji))
-class Attachment:
+class Attachment(Hashable):
"""Represents an attachment from Discord.
+ .. container:: operations
+
+ .. describe:: str(x)
+
+ Returns the URL of the attachment.
+
+ .. describe:: x == y
+
+ Checks if the attachment is equal to another attachment.
+
+ .. describe:: x != y
+
+ Checks if the attachment is not equal to another attachment.
+
+ .. describe:: hash(x)
+
+ Returns the hash of the attachment.
+
+ .. versionchanged:: 1.7
+ Attachment can now be casted to :class:`str` and is hashable.
+
Attributes
------------
id: :class:`int`
@@ -111,6 +132,9 @@ class Attachment:
def __repr__(self):
return '<Attachment id={0.id} filename={0.filename!r} url={0.url!r}>'.format(self)
+ def __str__(self):
+ return self.url or ''
+
async def save(self, fp, *, seek_begin=True, use_cached=False):
"""|coro|