mirror of
https://github.com/allthingslinux/tux.git
synced 2024-10-02 16:43:12 +00:00
fix(afk.py): improve AFK functionality error handling
This commit is contained in:
parent
7b5c19f9d3
commit
9bbb969c67
1 changed files with 10 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
|||
import contextlib
|
||||
from datetime import datetime, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
|
@ -30,7 +31,9 @@ class AFK(commands.Cog):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
reason : str
|
||||
ctx : commands.Context[Tux]
|
||||
The context of the command.
|
||||
reason : str, optional
|
||||
The reason you are AFK.
|
||||
"""
|
||||
|
||||
|
@ -51,7 +54,9 @@ class AFK(commands.Cog):
|
|||
new_name = f"[AFK] {target.display_name}"
|
||||
|
||||
await self.db.insert_afk(target.id, target.display_name, reason, ctx.guild.id)
|
||||
await target.edit(nick=new_name)
|
||||
|
||||
with contextlib.suppress(discord.Forbidden):
|
||||
await target.edit(nick=new_name)
|
||||
|
||||
return await ctx.send(
|
||||
content="\N{SLEEPING SYMBOL} || You are now afk! " + f"Reason: `{reason}`",
|
||||
|
@ -88,7 +93,9 @@ class AFK(commands.Cog):
|
|||
await self.db.remove_afk(message.author.id)
|
||||
|
||||
await message.reply("Welcome back!", delete_after=5)
|
||||
await message.author.edit(nick=entry.nickname)
|
||||
|
||||
with contextlib.suppress(discord.Forbidden):
|
||||
await message.author.edit(nick=entry.nickname)
|
||||
|
||||
@commands.Cog.listener("on_message")
|
||||
async def check_afk(self, message: discord.Message) -> None:
|
||||
|
|
Loading…
Reference in a new issue