Skip to content

Commit

Permalink
Implemented attachments in Webhook.edit_message and WebhookMessage.ed…
Browse files Browse the repository at this point in the history
  • Loading branch information
Vioshim authored and VincentRPS committed Jan 22, 2022
1 parent aed911d commit 5b980a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 12 additions & 0 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ async def edit_original_message(
embed: Optional[Embed] = MISSING,
file: File = MISSING,
files: List[File] = MISSING,
attachments: List[Attachment] = MISSING,
view: Optional[View] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
delete_after: Optional[float] = None,
Expand Down Expand Up @@ -306,6 +307,9 @@ async def edit_original_message(
files: List[:class:`File`]
A list of files to send with the content. This cannot be mixed with the
``file`` parameter.
attachments: List[:class:`Attachment`]
A list of attachments to keep in the message. If ``[]`` is passed
then all attachments are removed.
allowed_mentions: :class:`AllowedMentions`
Controls the mentions being processed in this message.
See :meth:`.abc.Messageable.send` for more information.
Expand Down Expand Up @@ -339,6 +343,7 @@ async def edit_original_message(
content=content,
file=file,
files=files,
attachments=attachments,
embed=embed,
embeds=embeds,
view=view,
Expand Down Expand Up @@ -818,6 +823,7 @@ async def edit(
embed: Optional[Embed] = MISSING,
file: File = MISSING,
files: List[File] = MISSING,
attachments: List[Attachment] = MISSING,
view: Optional[View] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
delete_after: Optional[float] = None,
Expand All @@ -840,6 +846,9 @@ async def edit(
files: List[:class:`File`]
A list of files to send with the content. This cannot be mixed with the
``file`` parameter.
attachments: List[:class:`Attachment`]
A list of attachments to keep in the message. If ``[]`` is passed
then all attachments are removed.
allowed_mentions: :class:`AllowedMentions`
Controls the mentions being processed in this message.
See :meth:`.abc.Messageable.send` for more information.
Expand Down Expand Up @@ -867,12 +876,15 @@ async def edit(
:class:`InteractionMessage`
The newly edited message.
"""
if attachments is MISSING:
attachments = self.attachments or MISSING
return await self._state._interaction.edit_original_message(
content=content,
embeds=embeds,
embed=embed,
file=file,
files=files,
attachments=attachments,
view=view,
allowed_mentions=allowed_mentions,
delete_after=delete_after
Expand Down
21 changes: 20 additions & 1 deletion discord/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from .. import utils
from ..object import Object
from ..errors import InvalidArgument, HTTPException, Forbidden, NotFound, DiscordServerError
from ..message import Message
from ..message import Attachment, Message
from ..enums import try_enum, WebhookType
from ..user import BaseUser, User
from ..asset import Asset
Expand Down Expand Up @@ -468,6 +468,7 @@ def handle_message_parameters(
ephemeral: bool = False,
file: File = MISSING,
files: List[File] = MISSING,
attachments: List[Attachment] = MISSING,
embed: Optional[Embed] = MISSING,
embeds: List[Embed] = MISSING,
view: Optional[View] = MISSING,
Expand Down Expand Up @@ -497,6 +498,9 @@ def handle_message_parameters(
else:
payload['content'] = None

if attachments is not MISSING:
payload['attachments'] = [a.to_dict() for a in attachments]

if view is not MISSING:
if view is not None:
payload['components'] = view.to_components()
Expand Down Expand Up @@ -683,6 +687,7 @@ async def edit(
embed: Optional[Embed] = MISSING,
file: File = MISSING,
files: List[File] = MISSING,
attachments: List[Attachment] = MISSING,
view: Optional[View] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
) -> WebhookMessage:
Expand Down Expand Up @@ -712,6 +717,11 @@ async def edit(
A list of files to send with the content. This cannot be mixed with the
``file`` parameter.
.. versionadded:: 2.0
attachments: List[:class:`Attachment`]
A list of attachments to keep in the message. If ``[]`` is passed
then all attachments are removed.
.. versionadded:: 2.0
allowed_mentions: :class:`AllowedMentions`
Controls the mentions being processed in this message.
Expand Down Expand Up @@ -746,13 +756,17 @@ async def edit(
elif isinstance(self.channel, Thread):
thread = Object(self.channel.id)

if attachments is MISSING:
attachments = self.attachments or MISSING

return await self._state._webhook.edit_message(
self.id,
content=content,
embeds=embeds,
embed=embed,
file=file,
files=files,
attachments=attachments,
view=view,
allowed_mentions=allowed_mentions,
thread=thread
Expand Down Expand Up @@ -1527,6 +1541,7 @@ async def edit_message(
embed: Optional[Embed] = MISSING,
file: File = MISSING,
files: List[File] = MISSING,
attachments: List[Attachment] = MISSING,
view: Optional[View] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
thread: Optional[Snowflake] = MISSING
Expand Down Expand Up @@ -1554,6 +1569,9 @@ async def edit_message(
embed: Optional[:class:`Embed`]
The embed to edit the message with. ``None`` suppresses the embeds.
This should not be mixed with the ``embeds`` parameter.
attachments: List[:class:`Attachment`]
A list of attachments to keep in the message. If ``[]`` is passed
then all attachments are removed.
file: :class:`File`
The file to upload. This cannot be mixed with ``files`` parameter.
Expand Down Expand Up @@ -1609,6 +1627,7 @@ async def edit_message(
content=content,
file=file,
files=files,
attachments=attachments,
embed=embed,
embeds=embeds,
view=view,
Expand Down

0 comments on commit 5b980a2

Please sign in to comment.