mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Add optional message to send when bot can't react in ctx.tick() and ctx.react_quietly() (#4092)
* Update context.py * Pre-emptive check to avoid hitting the API
This commit is contained in:
parent
a8f35f762c
commit
334cd4fa2a
@ -99,35 +99,52 @@ class Context(DPYContext):
|
||||
command = command or self.command
|
||||
await self.bot.send_help_for(self, command)
|
||||
|
||||
async def tick(self) -> bool:
|
||||
async def tick(self, *, message: Optional[str] = None) -> bool:
|
||||
"""Add a tick reaction to the command message.
|
||||
|
||||
Keyword Arguments
|
||||
-----------------
|
||||
message : str, optional
|
||||
The message to send if adding the reaction doesn't succeed.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
:code:`True` if adding the reaction succeeded.
|
||||
|
||||
"""
|
||||
try:
|
||||
await self.message.add_reaction(TICK)
|
||||
except discord.HTTPException:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
return await self.react_quietly(TICK, message=message)
|
||||
|
||||
async def react_quietly(
|
||||
self, reaction: Union[discord.Emoji, discord.Reaction, discord.PartialEmoji, str]
|
||||
self,
|
||||
reaction: Union[discord.Emoji, discord.Reaction, discord.PartialEmoji, str],
|
||||
*,
|
||||
message: Optional[str] = None,
|
||||
) -> bool:
|
||||
"""Adds a reaction to the command message.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
reaction : Union[discord.Emoji, discord.Reaction, discord.PartialEmoji, str]
|
||||
The emoji to react with.
|
||||
|
||||
Keyword Arguments
|
||||
-----------------
|
||||
message : str, optional
|
||||
The message to send if adding the reaction doesn't succeed.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
:code:`True` if adding the reaction succeeded.
|
||||
"""
|
||||
try:
|
||||
if not self.channel.permissions_for(self.me).add_reactions:
|
||||
raise RuntimeError
|
||||
await self.message.add_reaction(reaction)
|
||||
except discord.HTTPException:
|
||||
except (RuntimeError, discord.HTTPException):
|
||||
if message is not None:
|
||||
await self.send(message)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user