import discord import asyncio class UserManagementCommands: def __init__(self, bot): self.bot = bot async def cmd_close(self, message): """ Close the DM channel Usage: .close """ try: # Only works in DM channels if isinstance(message.channel, discord.DMChannel): await message.edit(content="✅ Closing DM...") await asyncio.sleep(1) # Give a second for the message to be seen await message.channel.close() else: await message.edit(content="❌ This command only works in DM channels.") except Exception as e: await message.edit(content=f"❌ Error closing DM: {str(e)}") async def cmd_block(self, message): """ Block a user using Discord's native block function Usage: .block @user or .block [in reply to a message] """ try: # Check if we have a mention or if it's a reply if message.mentions: user = message.mentions[0] elif message.reference and message.reference.resolved: user = message.reference.resolved.author else: await message.edit(content="❌ Usage: `.block @user` or reply to a message with `.block`") return if user == self.bot.user: await message.edit(content="❌ Cannot block yourself.") return await user.block() await message.edit(content=f"✅ Blocked {user.name}#{user.discriminator}") except Exception as e: await message.edit(content=f"❌ Error blocking user: {str(e)}") async def cmd_unblock(self, message): """ Unblock a user Usage: .unblock @user or user_id """ try: content = message.content.strip() # Check if we have a mention if message.mentions: user = message.mentions[0] await user.unblock() await message.edit(content=f"✅ Unblocked user {user.name}#{user.discriminator}.") return # Try to get user by ID parts = content.split() if len(parts) >= 2: try: user_id = int(parts[1]) user = await self.bot.fetch_user(user_id) await user.unblock() await message.edit(content=f"✅ Unblocked user {user.name}#{user.discriminator}.") except: await message.edit(content="❌ Could not find user with that ID.") else: await message.edit(content="❌ Usage: `.unblock @user` or `.unblock user_id`") except Exception as e: await message.edit(content=f"❌ Error unblocking user: {str(e)}") # Method to check if a channel is ignored def is_channel_ignored(self, channel_id): return channel_id in self.ignored_channels # Method to check if a channel is muted def is_channel_muted(self, channel_id): return channel_id in self.muted_channels