diff options
| author | 2022-11-26 14:11:27 +0400 | |
|---|---|---|
| committer | 2022-11-26 14:11:27 +0400 | |
| commit | fcf7e1cc2cdef58b27cc7d418f22b7bc22b78f07 (patch) | |
| tree | 5fcd9047957fe247d598b0a7cf6fea17f8c8e010 | |
| parent | Simplify Help Thread Warning Log (diff) | |
Handle Discord API Not Being Ready
When discord sends us the thread create event in help channels, it is
not ready to perform other operations on the thread such as getting or
pinning messages. This causes it to error out when we try to do these
actions and claim that those channels don't exist. Instead, we sleep for
a short time to try and wait for it to be ready.
Signed-off-by: Hassan Abouelela <[email protected]>
| -rw-r--r-- | bot/exts/help_channels/_channel.py | 7 | ||||
| -rw-r--r-- | bot/exts/help_channels/_cog.py | 3 |
2 files changed, 7 insertions, 3 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py index d4a742000..3dc9e81ef 100644 --- a/bot/exts/help_channels/_channel.py +++ b/bot/exts/help_channels/_channel.py @@ -1,5 +1,5 @@ """Contains all logic to handle changes to posts in the help forum.""" - +import asyncio import textwrap import discord @@ -109,6 +109,11 @@ async def help_thread_opened(opened_thread: discord.Thread, *, reopen: bool = Fa await _close_help_thread(opened_thread, _stats.ClosingReason.CLEANUP) return + # Discord sends the open event long before the thread is ready for actions in the API. + # This causes actions such as fetching the message, pinning message, etc to fail. + # We sleep here to try and delay our code enough so the thread is ready in the API. + await asyncio.sleep(2) + await send_opened_post_dm(opened_thread) if opened_thread.starter_message: diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py index 50f8416fc..bb2f43c5a 100644 --- a/bot/exts/help_channels/_cog.py +++ b/bot/exts/help_channels/_cog.py @@ -119,9 +119,8 @@ class HelpForum(commands.Cog): if thread.parent_id != self.help_forum_channel_id: return - await _channel.help_thread_opened(thread) - await self.post_with_disallowed_title_check(thread) + await _channel.help_thread_opened(thread) @commands.Cog.listener() async def on_thread_update(self, before: discord.Thread, after: discord.Thread) -> None: |