aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2020-10-02 19:52:23 +0100
committerGravatar wookie184 <[email protected]>2020-10-02 19:52:23 +0100
commitc035a756bac9f2d4c24dc232bda3a6d46b0c8a0f (patch)
treee708539ea3efca5069f62eacd44a0312238a7506
parentMerge pull request #860 from ks129/discord-py-upgrade-migrate (diff)
Changed send_attachments so kwargs could be given and would be passed to send()
-rw-r--r--bot/utils/messages.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/bot/utils/messages.py b/bot/utils/messages.py
index d0b2342b3..c4ac1e360 100644
--- a/bot/utils/messages.py
+++ b/bot/utils/messages.py
@@ -56,15 +56,22 @@ async def wait_for_deletion(
async def send_attachments(
message: discord.Message,
destination: Union[discord.TextChannel, discord.Webhook],
- link_large: bool = True
+ link_large: bool = True,
+ **kwargs
) -> List[str]:
"""
Re-upload the message's attachments to the destination and return a list of their new URLs.
Each attachment is sent as a separate message to more easily comply with the request/file size
limit. If link_large is True, attachments which are too large are instead grouped into a single
- embed which links to them.
+ embed which links to them. Extra kwargs will be passed to send() when sending the attachment.
"""
+ webhook_send_kwargs = {
+ 'username': sub_clyde(message.author.display_name),
+ 'avatar_url': message.author.avatar_url,
+ }
+ webhook_send_kwargs.update(kwargs)
+
large = []
urls = []
for attachment in message.attachments:
@@ -82,14 +89,10 @@ async def send_attachments(
attachment_file = discord.File(file, filename=attachment.filename)
if isinstance(destination, discord.TextChannel):
- msg = await destination.send(file=attachment_file)
+ msg = await destination.send(file=attachment_file, **kwargs)
urls.append(msg.attachments[0].url)
else:
- await destination.send(
- file=attachment_file,
- username=sub_clyde(message.author.display_name),
- avatar_url=message.author.avatar_url
- )
+ await destination.send(file=attachment_file, **webhook_send_kwargs)
elif link_large:
large.append(attachment)
else:
@@ -106,13 +109,9 @@ async def send_attachments(
embed.set_footer(text="Attachments exceed upload size limit.")
if isinstance(destination, discord.TextChannel):
- await destination.send(embed=embed)
+ await destination.send(embed=embed, **kwargs)
else:
- await destination.send(
- embed=embed,
- username=sub_clyde(message.author.display_name),
- avatar_url=message.author.avatar_url
- )
+ await destination.send(embed=embed, **webhook_send_kwargs)
return urls