import discord, toml from discord.ext import commands from discord.commands import option with open("config.toml", "r") as f: config = toml.load(f) guild_ids=config["bot"]["guild_ids"] class EssentialCommands(commands.Cog): def __init__(self, bot): self.bot = bot @commands.slash_command(guild_ids=guild_ids) async def ping(self, ctx): await ctx.respond('Pong!') @commands.slash_command(guild_ids=guild_ids) @option('msg', description="The message to say.") async def say(self, ctx, message): await ctx.send(message) @commands.slash_command(guild_ids=guild_ids) async def serverinfo(self, ctx): await ctx.defer() embed = discord.Embed(title=f"{ctx.guild.name} Info", colour=discord.Colour.blurple()) embed.add_field(name="Roles", value=len(ctx.guild.roles), inline=False) embed.add_field(name="Members", value=ctx.guild.member_count, inline=False) embed.add_field(name="Owner", value=ctx.guild.owner.mention, inline=False) embed.add_field(name="Text Channels", value=len(ctx.guild.text_channels), inline=False) embed.add_field(name="Voice Channels", value=len(ctx.guild.voice_channels), inline=False) embed.add_field(name="Boost Level", value=ctx.guild.premium_tier, inline=False) embed.add_field(name="Created", value=ctx.guild.created_at, inline=False) embed.add_field(name="ID", value=ctx.guild.id, inline=False) embed.add_field(name="Max File Size", value=f"{str(int(ctx.guild.filesize_limit / (1024 * 1024)))} MB", inline=False) icon = ctx.guild.icon embed.set_thumbnail(url=icon) await ctx.followup.send(embed=embed) @commands.slash_command(guild_ids=guild_ids) @option('ammount', description="The of messages to clear.", required=True) @commands.has_permissions(manage_messages=True) async def clean(self, ctx, amount: int = 10): await ctx.defer() try: await ctx.channel.purge(limit=amount + 1) except: await ctx.followup.send(f"Could not purge all of the messages.") else: await ctx.followup.send(f"Purged {amount} messages.") @commands.slash_command(guild_ids=guild_ids) @commands.has_permissions(manage_channels=True) async def lock(self, ctx, *, reason=None): await ctx.defer() channel = ctx.channel overwrite = channel.overwrites_for(ctx.guild.default_role) overwrite.send_messages = False await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite) embed = discord.Embed(title="Locked", description=f"Reason: {reason}") await ctx.followup.send(embed=embed) @commands.slash_command(guild_ids=guild_ids) @commands.has_permissions(manage_channels=True) async def unlock(self, ctx, *, reason=None): await ctx.defer() channel = ctx.channel overwrite = channel.overwrites_for(ctx.guild.default_role) overwrite.send_messages = True await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite) embed = discord.Embed(title="Unlocked", description=f"Reason: {reason}") await ctx.followup.send(embed=embed) @commands.slash_command(guild_ids=guild_ids) @commands.has_permissions(manage_channels=True) async def lockdown(self, ctx, *, reason=None): await ctx.defer() for channel in ctx.guild.channels: if isinstance(channel, discord.TextChannel): overwrite = channel.overwrites_for(ctx.guild.default_role) overwrite.send_messages = False await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite) embed = discord.Embed(title="Server Locked Down", description=f"Reason: {reason}") await ctx.followup.send(embed=embed) @commands.slash_command(guild_ids=guild_ids) @commands.has_permissions(manage_channels=True) async def unlockdown(self, ctx): await ctx.defer() for channel in ctx.guild.channels: if isinstance(channel, discord.TextChannel): overwrite = channel.overwrites_for(ctx.guild.default_role) overwrite.send_messages = None await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite) embed = discord.Embed(title="Server Unlocked", description="All channels have been unlocked.") await ctx.followup.send(embed=embed) @commands.slash_command(guild_ids=guild_ids) @option('user', description="The username of the user you want the avatars picture incl 1234 numbers", required=True) async def avatar(self, ctx, member: discord.Member): try: avatar_url = member.avatar.url except: await ctx.respond(f"Unable to get {member.name}'s avatar as he probably has a default avatar.") else: await ctx.respond(f"{member.name}'s avatar: {avatar_url}") @commands.slash_command(guild_ids=guild_ids) @option('member', description="The username of the user to run the check on.") async def whois(self, ctx, member: discord.Member = None): member = member or ctx.author roles = [role.mention for role in member.roles[1:]] if not roles: roles = ["None"] embed = discord.Embed(title=f"{member.display_name}'s Info", color=member.color) try: embed.set_thumbnail(url=member.avatar.url) except: pass embed.add_field(name="Name", value=str(member), inline=False) embed.add_field(name="ID", value=member.id, inline=False) embed.add_field(name="Account Created", value=member.created_at.strftime("%d/%m/%Y %H:%M:%S"), inline=False) embed.add_field(name="Join Date", value=member.joined_at.strftime("%d/%m/%Y %H:%M:%S"), inline=False) embed.add_field(name="Roles", value=" ".join(roles), inline=False) await ctx.send(embed=embed) @commands.slash_command(guild_ids=guild_ids) @option('title', description="The biggest text.", required=True) @option('content', description="The actuall text to put in the embed.", required=True) @option('footer', description="The lower text.", required=False) @option('color', description="The color as a word example: Color: dark_blue", required=False) async def embed(self, ctx, title: str, content: str, color: str = None, footer: str = None): embed = discord.Embed(title=title, description=content) if color: try: atr = getattr(discord.Color, color) embed.color = atr() except Exception as e: bot.api.logger("inf", f"Command ivoked a error wrong color: {e}") ctx.send("ERR: Invalid color.") return 1 if footer: embed.set_footer(text=footer) await ctx.send(embed=embed) def setup(bot): bot.add_cog(EssentialCommands(bot))