mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -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
|
command = command or self.command
|
||||||
await self.bot.send_help_for(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.
|
"""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
|
Returns
|
||||||
-------
|
-------
|
||||||
bool
|
bool
|
||||||
:code:`True` if adding the reaction succeeded.
|
:code:`True` if adding the reaction succeeded.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
return await self.react_quietly(TICK, message=message)
|
||||||
await self.message.add_reaction(TICK)
|
|
||||||
except discord.HTTPException:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
async def react_quietly(
|
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:
|
) -> bool:
|
||||||
"""Adds a reaction to the command message.
|
"""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
|
Returns
|
||||||
-------
|
-------
|
||||||
bool
|
bool
|
||||||
:code:`True` if adding the reaction succeeded.
|
:code:`True` if adding the reaction succeeded.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
if not self.channel.permissions_for(self.me).add_reactions:
|
||||||
|
raise RuntimeError
|
||||||
await self.message.add_reaction(reaction)
|
await self.message.add_reaction(reaction)
|
||||||
except discord.HTTPException:
|
except (RuntimeError, discord.HTTPException):
|
||||||
|
if message is not None:
|
||||||
|
await self.send(message)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user