diff options
| author | NCPlayz <[email protected]> | 2019-11-20 19:57:34 +0000 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-12-20 20:56:40 -0500 |
| commit | 9c6a121644a33ab27f00c5241a90fdfcc07f3ffa (patch) | |
| tree | 369f32fc26e0e1840b664adc83eed23860a5509e /discord/message.py | |
| parent | Default the Streaming name to the one passed for user created ones. (diff) | |
| download | discord.py-9c6a121644a33ab27f00c5241a90fdfcc07f3ffa.tar.xz discord.py-9c6a121644a33ab27f00c5241a90fdfcc07f3ffa.zip | |
Implement discord.MessageFlags
Refactor flags placement and use it for suppression.
Diffstat (limited to 'discord/message.py')
| -rw-r--r-- | discord/message.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/discord/message.py b/discord/message.py index 1fd2245a..01ef34db 100644 --- a/discord/message.py +++ b/discord/message.py @@ -38,6 +38,7 @@ from .enums import MessageType, try_enum from .errors import InvalidArgument, ClientException, HTTPException from .embeds import Embed from .member import Member +from .flags import MessageFlags class Attachment: """Represents an attachment from Discord. @@ -237,6 +238,8 @@ class Message: A list of attachments given to a message. pinned: :class:`bool` Specifies if the message is currently pinned. + flags: :class:`MessageFlags` + Extra features of the message. reactions : List[:class:`Reaction`] Reactions to a message. Reactions can be either custom emoji or standard unicode emoji. activity: Optional[:class:`dict`] @@ -263,7 +266,7 @@ class Message: 'mention_everyone', 'embeds', 'id', 'mentions', 'author', '_cs_channel_mentions', '_cs_raw_mentions', 'attachments', '_cs_clean_content', '_cs_raw_channel_mentions', 'nonce', 'pinned', - 'role_mentions', '_cs_raw_role_mentions', 'type', 'call', + 'role_mentions', '_cs_raw_role_mentions', 'type', 'call', 'flags', '_cs_system_content', '_cs_guild', '_state', 'reactions', 'application', 'activity') @@ -280,19 +283,20 @@ class Message: self._edited_timestamp = utils.parse_time(data['edited_timestamp']) self.type = try_enum(MessageType, data['type']) self.pinned = data['pinned'] + self.flags = MessageFlags._from_value(data.get('flags', 0)) self.mention_everyone = data['mention_everyone'] self.tts = data['tts'] self.content = data['content'] self.nonce = data.get('nonce') - for handler in ('author', 'member', 'mentions', 'mention_roles', 'call'): + for handler in ('author', 'member', 'mentions', 'mention_roles', 'call', 'flags'): try: getattr(self, '_handle_%s' % handler)(data[handler]) except KeyError: continue def __repr__(self): - return '<Message id={0.id} channel={0.channel!r} type={0.type!r} author={0.author!r}>'.format(self) + return '<Message id={0.id} channel={0.channel!r} type={0.type!r} author={0.author!r} flags={0.flags!r}>'.format(self) def _try_patch(self, data, key, transform=None): try: @@ -361,6 +365,9 @@ class Message: def _handle_pinned(self, value): self.pinned = value + def _handle_flags(self, value): + self.flags = MessageFlags._from_value(value) + def _handle_application(self, value): self.application = value @@ -772,7 +779,9 @@ class Message: except KeyError: pass else: - await self._state.http.suppress_message_embeds(self.channel.id, self.id, suppress=suppress) + flags = MessageFlags._from_value(self.flags.value) + flags.suppress_embeds = suppress + fields['flags'] = flags.value delete_after = fields.pop('delete_after', None) @@ -783,6 +792,27 @@ class Message: if delete_after is not None: await self.delete(delay=delete_after) + async def publish(self): + """|coro| + + Publishes this message to your announcement channel. + + You must have the :attr:`~Permissions.manage_messages` permission to use this. + + .. note:: + + This can only be used by non-bot accounts. + + Raises + ------- + Forbidden + You do not have the proper permissions to publish this message. + HTTPException + Publishing the message failed. + """ + + await self._state.http.publish_message(self.channel.id, self.id) + async def pin(self): """|coro| |