mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Core] Support setting avatar via attachment (#3747)
* [Core] Support avatars via attachments * Fix the thing I was actually annoyed about. * Updated error texts * English is a damn annoying language.
This commit is contained in:
parent
b8ac70e59a
commit
10ad2a559a
@ -1095,11 +1095,21 @@ class Core(commands.Cog, CoreLogic):
|
||||
|
||||
@_set.command()
|
||||
@checks.is_owner()
|
||||
async def avatar(self, ctx: commands.Context, url: str):
|
||||
"""Sets [botname]'s avatar"""
|
||||
async def avatar(self, ctx: commands.Context, url: str = None):
|
||||
"""Sets [botname]'s avatar
|
||||
|
||||
Supports either an attachment or an image URL."""
|
||||
if len(ctx.message.attachments) > 0: # Attachments take priority
|
||||
data = await ctx.message.attachments[0].read()
|
||||
elif url is not None:
|
||||
if url.startswith("<") and url.endswith(">"):
|
||||
url = url[1:-1]
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as r:
|
||||
data = await r.read()
|
||||
else:
|
||||
return await ctx.send(_("Please upload an attachment or provide an URL link."))
|
||||
|
||||
try:
|
||||
await ctx.bot.user.edit(avatar=data)
|
||||
@ -1107,8 +1117,8 @@ class Core(commands.Cog, CoreLogic):
|
||||
await ctx.send(
|
||||
_(
|
||||
"Failed. Remember that you can edit my avatar "
|
||||
"up to two times a hour. The URL must be a "
|
||||
"direct link to a JPG / PNG."
|
||||
"up to two times a hour. The URL or attachment "
|
||||
"must be a valid image in either JPG or PNG format."
|
||||
)
|
||||
)
|
||||
except discord.InvalidArgument:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user