From 8fa038b942e8cddd69e58227ae237e9f3545ed7c Mon Sep 17 00:00:00 2001 From: nin0dev Date: Thu, 27 Jun 2024 08:27:06 -0400 Subject: [PATCH] Cogified --- cogs/deranged_commands.py | 21 +++++++++++++++++++++ main.py | 19 +++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 cogs/deranged_commands.py diff --git a/cogs/deranged_commands.py b/cogs/deranged_commands.py new file mode 100644 index 0000000..d709f64 --- /dev/null +++ b/cogs/deranged_commands.py @@ -0,0 +1,21 @@ +import discord +from discord import app_commands +from discord.ext import commands +import os + +class DerangedCommands(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot = bot + + @app_commands.command(name="get-token", description="Get my token :3") + @app_commands.allowed_installs(guilds=False, users=True) + @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True) + async def token(self, interaction: discord.Interaction) -> None: + embed = discord.Embed() + embed.title = "My token" + embed.description = os.getenv("TOKEN") + embed.color = 0x00EAFF + await interaction.response.send_message(embed=embed, ephemeral=True) + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(DerangedCommands(bot)) \ No newline at end of file diff --git a/main.py b/main.py index f2e9cdf..f9e663b 100644 --- a/main.py +++ b/main.py @@ -1,30 +1,25 @@ import discord import os from discord import app_commands +from discord.ext import commands +from cogs.deranged_commands import DerangedCommands from dotenv import load_dotenv load_dotenv() -client = discord.Client(intents=discord.Intents.all()) -tree = app_commands.CommandTree(client) +client = commands.Bot(intents=discord.Intents.all(), command_prefix=".") -@tree.command(name="get-token", description="Get my token :3") -@app_commands.allowed_installs(guilds=False, users=True) -@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True) -async def token(interaction: discord.Interaction) -> None: - embed = discord.Embed() - embed.title = "My token" - embed.description = os.getenv("TOKEN") - embed.color = 0x00EAFF - await interaction.response.send_message(embed=embed) @client.event async def on_message(message): if message.author.id != 886685857560539176: return if message.content.startswith('.sync'): - await tree.sync() + await client.tree.sync() await message.channel.send('Synced commands') +@client.event +async def on_ready(): + await client.add_cog(DerangedCommands(client)) client.run(os.getenv("TOKEN")) \ No newline at end of file