Skip to content

Commit 7812a1d

Browse files
Avoid waiting for message when bot will not see it
Previously, the code below the if-statement will always execute if eat is False. In guilds where the bot only has the applications.commands scope, or guilds with the bot scope where the bot cannot read the channel's messages, the bot will not find SlashContext.message and will time out after 3 seconds. This unnecessary wait slows down command execution. With this change, the bot will only check for messages if one of the following conditions are true: - SlashContext.guild_id is None (i.e. command executed in a private DM) or - SlashContext.channel is not None (i.e. command executed in a guild with the bot scope), and the bot has permission to view messages in the command's channel.
1 parent 9cb4bb3 commit 7812a1d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

discord_slash/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async def respond(self, eat: bool = False):
9191
base = {"type": 2 if eat else 5}
9292
_task = self.bot.loop.create_task(self._http.post(base, self.interaction_id, self.__token, True))
9393
self.sent = True
94-
if not eat:
94+
if not eat and (not self.guild_id or (self.channel and self.channel.permissions_for(self.guild.me).view_channel)):
9595
with suppress(asyncio.TimeoutError):
9696
def check(message: discord.Message):
9797
user_id = self.author_id

0 commit comments

Comments
 (0)