mirror of
https://github.com/allthingslinux/tux.git
synced 2024-10-03 00:53: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 datetime import datetime, timedelta
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
@ -30,7 +31,9 @@ class AFK(commands.Cog):
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
reason : str
|
ctx : commands.Context[Tux]
|
||||||
|
The context of the command.
|
||||||
|
reason : str, optional
|
||||||
The reason you are AFK.
|
The reason you are AFK.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -51,6 +54,8 @@ class AFK(commands.Cog):
|
||||||
new_name = f"[AFK] {target.display_name}"
|
new_name = f"[AFK] {target.display_name}"
|
||||||
|
|
||||||
await self.db.insert_afk(target.id, target.display_name, reason, ctx.guild.id)
|
await self.db.insert_afk(target.id, target.display_name, reason, ctx.guild.id)
|
||||||
|
|
||||||
|
with contextlib.suppress(discord.Forbidden):
|
||||||
await target.edit(nick=new_name)
|
await target.edit(nick=new_name)
|
||||||
|
|
||||||
return await ctx.send(
|
return await ctx.send(
|
||||||
|
@ -88,6 +93,8 @@ class AFK(commands.Cog):
|
||||||
await self.db.remove_afk(message.author.id)
|
await self.db.remove_afk(message.author.id)
|
||||||
|
|
||||||
await message.reply("Welcome back!", delete_after=5)
|
await message.reply("Welcome back!", delete_after=5)
|
||||||
|
|
||||||
|
with contextlib.suppress(discord.Forbidden):
|
||||||
await message.author.edit(nick=entry.nickname)
|
await message.author.edit(nick=entry.nickname)
|
||||||
|
|
||||||
@commands.Cog.listener("on_message")
|
@commands.Cog.listener("on_message")
|
||||||
|
|
Loading…
Reference in a new issue