import discord from discord import app_commands from discord.ext import commands class Channel(commands.Cog): def __init__(self, bot): self.bot = bot @commands.Cog.listener() async def on_ready(self): print("Channel Online") channel = app_commands.Group(name="channel", description="Manage channels in the server") @channel.command(name="lock", description="Disable messaging in the specified channel for users with the default role") @commands.has_permissions(manage_channels=True) async def lock(self, interaction: discord.Interaction, channel: discord.TextChannel = None): if channel is None: channel = interaction.channel await channel.set_permissions(interaction.guild.default_role, send_messages=False) await interaction.response.send_message(f"Users with {interaction.guild.default_role} cannot type in {channel.mention}", ephemeral=True) @channel.command(name="unlock", description="Unlock a channel") @commands.has_permissions(manage_channels=True) async def unlock(self, interaction: discord.Interaction, channel: discord.TextChannel = None): if channel is None: channel = interaction.channel await channel.set_permissions(interaction.guild.default_role, send_messages=True) await interaction.response.send_message(f"Users with {interaction.guild.default_role} can now type in {channel.mention}", ephemeral=True) @channel.command(name="slowmode", description="Set the channels slowmode") @commands.has_permissions(manage_channels=True) async def slowmode(self, interaction: discord.Interaction, seconds: int = None, *, channel: discord.TextChannel = None): if channel is None: channel = interaction.channel if seconds is None or seconds == 0: await channel.edit(slowmode_delay=0) await interaction.response.send_message(f"Slowmode in {channel.mention} has been disabled.") return await channel.edit(slowmode_delay=seconds) await interaction.response.send_message(f"Set the slowmode of {channel.mention} to {seconds} seconds") @channel.command(name="clear", description="Bulk deletes messages") @commands.has_permissions(manage_messages=True) async def clear(self, interaction: discord.Interaction, amount: int): await interaction.response.send_message(f"Deleted {amount} messages", ephemeral=True, delete_after=2) await interaction.channel.purge(limit=amount) async def setup(bot): await bot.add_cog(Channel(bot))