import discord import aiohttp import aiofiles import inspect from discord.ext import commands from main import colors from modules.utils.paginate import paginate class Dev(commands.Cog): def __init__(self, bot): self.bot = bot async def cog_check(self, ctx): return ctx.author.id == self.bot.owner_id or ctx.author.id in self.bot.config['OwnerIds'] @commands.command(name='setavatar', aliases=['sav']) async def set_avatar(self, ctx, url: str): async with aiohttp.ClientSession() as session: async with session.get(url) as response: if response.status != 200: return await ctx.send('Failed to download the image.') data = await response.read() await self.bot.user.edit(avatar=data) await ctx.send('Avatar updated successfully.') @commands.command(name='setstatus', aliases=['ss']) async def set_status(self, ctx, *, status: str): status_dict = { 'online': discord.Status.online, 'idle': discord.Status.idle, 'dnd': discord.Status.dnd, 'invisible': discord.Status.invisible } await self.bot.change_presence(status=status_dict.get(status.lower(), discord.Status.online)) await ctx.send(f'Status set to {status}.') @commands.command(name='eval') async def _eval(self, ctx, *, code): if ctx.author.id != self.bot.owner_id: return await ctx.send("You do not have permission to use this command.") try: result = eval(code) if inspect.isawaitable(result): result = await result await ctx.send(f'```bash\n{result}\n```') except Exception as e: await ctx.send(f'```bash\n{type(e).__name__}: {e}\n```') @commands.command(name='listservermembers', aliases=['lsm']) async def list_server_members(self, ctx): members = ctx.guild.members members_list = '\n'.join([f'{member.name}#{member.discriminator}' for member in members]) await ctx.send(f'```Members of {ctx.guild.name}:\n{members_list}\n```') @commands.command(name='reload') async def reload(self, ctx, *, module): try: await self.bot.reload_extension(f'modules.{module}') await ctx.send(f'Module {module} reloaded successfully.') except Exception as e: await ctx.send(f'Failed to reload module {module}.\nError: {type(e).__name__} - {e}') @commands.command(name='leave') async def leave(self, ctx, guild_id: int): guild = self.bot.get_guild(guild_id) if guild: await guild.leave() await ctx.send(f'Left guild {guild.name} ({guild_id})') else: await ctx.send(f'Guild with ID {guild_id} not found.') @commands.command(name='leaveemptyservers', aliases=['les']) async def leave_empty_servers(self, ctx): left_guilds = [] for guild in self.bot.guilds: if len(guild.members) == 1: await guild.leave() left_guilds.append(guild.name) await ctx.send(f'Left guilds: {", ".join(left_guilds)}') @commands.command(name='shutdown', aliases=['die']) async def shutdown(self, ctx): await ctx.message.add_reaction('✅') await self.bot.close() @commands.command(name='setname', aliases=['sn']) async def set_name(self, ctx, *, name: str): await self.bot.user.edit(username=name) await ctx.send(f'Bot name changed to {name}') @commands.command(name='setbotbanner', aliases=['sbb']) async def setbotbanner(self, ctx, url: str): async with aiohttp.ClientSession() as session: async with session.get(url) as response: if response.status != 200: return await ctx.send('Failed to download the image.') data = await response.read() await self.bot.user.edit(banner=data) await ctx.send('Banner updated successfully.') @commands.command(name='send') async def send(self, ctx, target_type: str, target_id: int, *, message: str): if target_type.lower() == 'channel': target = self.bot.get_channel(target_id) elif target_type.lower() == 'user': target = self.bot.get_user(target_id) else: return await ctx.send('Invalid target type. Use "channel" or "user".') if target: await target.send(message) await ctx.send('Message sent successfully.') else: await ctx.send('Target not found.') @commands.command(name='savechat') async def save_chat(self, ctx, limit: int): messages = await ctx.channel.history(limit=limit).flatten() filename = f"chat_{ctx.channel.id}.txt" async with aiofiles.open(filename, 'w') as file: for message in messages: await file.write(f'{message.author.name}: {message.content}\n') await ctx.author.send(file=discord.File(filename)) await ctx.send(f'Saved {limit} messages and sent the file to your DMs.') @commands.command() async def sync(self, ctx): await self.bot.tree.sync() await ctx.send("Commands synced.") print("Commands synced.") @commands.hybrid_command() async def listservers(self, ctx: commands.Context): servers = self.bot.guilds if not servers: return await ctx.send("The bot is not part of any servers.") pages = [] servers_per_page = 15 for i in range(0, len(servers), servers_per_page): embed = discord.Embed( title="Server List", color=colors['default'] ) for guild in servers[i:i + servers_per_page]: embed.add_field( name=guild.name, value=f"ID: {guild.id}\nMembers: {guild.member_count}", inline=False ) pages.append(embed) await paginate(ctx, pages) async def setup(bot): await bot.add_cog(Dev(bot))