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()
|
@_set.command()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
async def avatar(self, ctx: commands.Context, url: str):
|
async def avatar(self, ctx: commands.Context, url: str = None):
|
||||||
"""Sets [botname]'s avatar"""
|
"""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 aiohttp.ClientSession() as session:
|
||||||
async with session.get(url) as r:
|
async with session.get(url) as r:
|
||||||
data = await r.read()
|
data = await r.read()
|
||||||
|
else:
|
||||||
|
return await ctx.send(_("Please upload an attachment or provide an URL link."))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await ctx.bot.user.edit(avatar=data)
|
await ctx.bot.user.edit(avatar=data)
|
||||||
@ -1107,8 +1117,8 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
await ctx.send(
|
await ctx.send(
|
||||||
_(
|
_(
|
||||||
"Failed. Remember that you can edit my avatar "
|
"Failed. Remember that you can edit my avatar "
|
||||||
"up to two times a hour. The URL must be a "
|
"up to two times a hour. The URL or attachment "
|
||||||
"direct link to a JPG / PNG."
|
"must be a valid image in either JPG or PNG format."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except discord.InvalidArgument:
|
except discord.InvalidArgument:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user