class AfkCommands: def __init__(self, bot): self.bot = bot async def handle_afk_dm(self, message): """Handle DMs when in AFK mode""" if self.bot.AFK_STATUS and message.author.id not in self.bot.AFK_NOTIFIED_USERS: self.bot.AFK_NOTIFIED_USERS.append(message.author.id) await message.reply( "Heya, I'm not at my computer right now, if you're requesting something please follow . I'll let you know when I'm back :) \n\n-# This action was automated." ) await message.channel.send(f"AFK reason:\n{self.bot.AFK_REASON}") async def cmd_afk(self, message): """Enable AFK mode""" if not self.bot.AFK_STATUS: self.bot.AFK_STATUS = True try: self.bot.AFK_REASON = message.content[5:] except IndexError: pass finally: if not self.bot.AFK_REASON.strip(): self.bot.AFK_REASON = "None" await message.reply("k") else: await message.reply("You are already in AFK mode.", silent=True) async def cmd_unafk(self, message): """Disable AFK mode""" if self.bot.AFK_STATUS: self.bot.AFK_STATUS = False for i in self.bot.AFK_NOTIFIED_USERS: try: user = await self.bot.fetch_user(i) if user: dm_channel = await user.create_dm() await dm_channel.send("Hey, I'm back, human me will take over now!") except Exception as e: raise RuntimeWarning from e messaged_users_string = "" for i in self.bot.AFK_NOTIFIED_USERS: try: user = await self.bot.fetch_user(i) if user: messaged_users_string += f"\n\\- {user.id} | {user.name}" except Exception as e: raise RuntimeWarning from e await message.reply(f"should work, here are the people who dmed you:" + (messaged_users_string if messaged_users_string else "\nnobody because you're alone asf obvs")) self.bot.AFK_NOTIFIED_USERS.clear() else: await message.reply("You are not in AFK mode.", silent=True)