diff options
author | 2020-03-14 19:44:32 +0100 | |
---|---|---|
committer | 2020-03-14 19:44:32 +0100 | |
commit | 0cee9682212252a9b27ae2b9a1f7afbf4548e38b (patch) | |
tree | efd7b3b8ab6362dc362a49dbe5b87dffc57f5822 /bot/bot.py | |
parent | Deseasonify: add convenience method to get season by name (diff) |
Deseasonify: add `set_banner` method to SeasonalBot
Diffstat (limited to 'bot/bot.py')
-rw-r--r-- | bot/bot.py | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -92,6 +92,24 @@ class SeasonalBot(commands.Bot): log.warning(f"Changing avatar failed: {url}") return False + async def set_banner(self, url: str) -> bool: + """Sets the guild's banner based on the provided `url`.""" + guild = bot.get_guild(Client.guild) + old_banner = guild.banner + + image = await self._fetch_image(url) + with contextlib.suppress(discord.HTTPException, asyncio.TimeoutError): + async with async_timeout.timeout(5): + await guild.edit(banner=image) + + new_banner = bot.get_guild(Client.guild).banner + if new_banner != old_banner: + log.debug(f"Banner changed to {url}") + return True + + log.warning(f"Changing banner failed: {url}") + return False + async def set_icon(self, url: str) -> bool: """Sets the guild's icon based on a URL.""" guild = bot.get_guild(Client.guild) |