Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command: Avatar #3333

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions cogs/utility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import aiohttp
import inspect
import os
import random
Expand Down Expand Up @@ -2120,6 +2121,47 @@ def paginate(text: str):

await self.bot.add_reaction(ctx.message, "\u2705")

@commands.command(name="avatar")
@checks.has_permissions(PermissionLevel.OWNER)
async def avatar(self, ctx: commands.Context, url: str = None):
"""
Updates the bots avatar within discord.
"""
if not ctx.message.attachments and url is None:
embed = discord.Embed(
title="Error",
description="You need to upload or link a image file.",
color=self.bot.error_color,
)
return await ctx.send(embed=embed)
dc_avatar = None
if ctx.message.attachments:
dc_avatar = await ctx.message.attachments[0].read()
elif url:
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
dc_avatar = await resp.read()

if dc_avatar is None:
embed = discord.Embed(
title="Error",
description="Reading the attachment failed, is it valid?",
color=self.bot.error_color,
)
return await ctx.send(embed=embed)
try:
await self.bot.user.edit(avatar=dc_avatar)
logger.info("Bot Avatar updated.")
except Exception:
raise ValueError("Uploading the avatar to discord failed.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it handles the exception gracefully, the command will just error silently giving no feedback to the user indicating the command has failed. Ideally this also should invoke @trigger_typing since it could take a few seconds to complete.


embed = discord.Embed(
title="Successfully updated",
description="Successfully updated avatar.",
color=self.bot.main_color,
)
await ctx.send(embed=embed)


async def setup(bot):
await bot.add_cog(Utility(bot))