You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
5.4 KiB
Python

2 years ago
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('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))