diff options
author | 2021-08-31 17:30:14 +0100 | |
---|---|---|
committer | 2021-08-31 17:30:14 +0100 | |
commit | c66be4adba72c6ef79d4a1e720b4925f1c57241a (patch) | |
tree | 9be6db3d80e183cfd05963699706aac9ffc46b96 /bot/bot.py | |
parent | Merge pull request #831 from brad90four/patch-1 (diff) | |
parent | Snakes: make use of PLAYER_ICON_IMAGE_SIZE again (diff) |
Merge pull request #835 from python-discord/discord-2.0
Migrate to Discord 2.0a0
Diffstat (limited to 'bot/bot.py')
-rw-r--r-- | bot/bot.py | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -1,13 +1,15 @@ import asyncio import logging import socket +from contextlib import suppress from typing import Optional import discord from aiohttp import AsyncResolver, ClientSession, TCPConnector from async_rediscache import RedisSession -from discord import DiscordException, Embed +from discord import DiscordException, Embed, Forbidden, Thread from discord.ext import commands +from discord.ext.commands import Cog, when_mentioned_or from bot import constants @@ -45,6 +47,21 @@ class Bot(commands.Bot): return None return guild.me + @Cog.listener() + async def on_thread_join(self, thread: Thread) -> None: + """ + Try to join newly created threads. + + Despite the event name being misleading, this is dispatched when new threads are created. + We want our bots to automatically join threads in order to answer commands using their prefixes. + """ + if thread.me: + # Already in this thread, return early + return + + with suppress(Forbidden): + await thread.join() + async def close(self) -> None: """Close Redis session when bot is shutting down.""" await super().close() @@ -120,7 +137,7 @@ class Bot(commands.Bot): return if not icon: - icon = self.user.avatar_url_as(format="png") + icon = self.user.display_avatar.url embed = Embed(description=details) embed.set_author(name=title, icon_url=icon) @@ -203,7 +220,7 @@ loop.run_until_complete(redis_session.connect()) bot = Bot( redis_session=redis_session, - command_prefix=constants.Client.prefix, + command_prefix=when_mentioned_or(constants.Client.prefix), activity=discord.Game(name=f"Commands: {constants.Client.prefix}help"), allowed_mentions=discord.AllowedMentions(everyone=False, roles=_allowed_roles), intents=_intents, |