from datetime import datetime import aiosqlite import discord from discord import SlashCommandGroup from discord.ext import commands from apply.applyembeds import StudioEmbed, CCEmbed, PlayerEmbed, StaffEmbed class ApplicationSystem(commands.Cog): def __init__(self, bot): self.bot = bot self.persistent_views_added = False self.staff_embed = StaffEmbed(bot) self.player_embed = PlayerEmbed(bot) self.studio_embed = StudioEmbed(bot) self.cc_embed = CCEmbed(bot) @commands.Cog.listener() async def on_ready(self): if not self.persistent_views_added: self.bot.add_view(ApplySelect()) self.persistent_views_added = True async with aiosqlite.connect("database/userdata.db") as db: await db.execute(""" CREATE TABLE IF NOT EXISTS users ( user_id INTEGER, option_selected TEXT ) """) await db.commit() ticket_group = SlashCommandGroup( name="set", description="Setze das Applysstem", guild_only=True ) @ticket_group.command( name="apply", description="Setze das Applysstem", ) async def set_apply(self, ctx: discord.ApplicationCommandInvokeError): embed = discord.Embed( title="asda", description="asdasd", color=discord.Color.random(), timestamp=datetime.now() ) embed.set_footer(text=f"{ctx.guild.name}", icon_url=self.bot.user.avatar.url) await ctx.respond(embed=embed, view=ApplySelect()) class ApplySelect(discord.ui.View): def __init__(self): super().__init__(timeout=None) self.bot = None self.view_id = "apply_select" options = [ discord.SelectOption( label="Staff Bewerbung", description="Hier kannst du dich als Staff-Member Bewerben", emoji="🔰", ), discord.SelectOption( label="Player Bewerbung", description="Hier kannst du dich als Player Bewerben", emoji="👤", ), discord.SelectOption( label="Studio Bewerbung", description="Hier kannst du dich als GFX oder VFX Bewerben", emoji="🎨", ), discord.SelectOption( label="Content Creator Bewerbung", description="Hier kannst du dich als Content Creator Bewerben", emoji="🎥", ), ] @discord.ui.select( placeholder="🀄️ | Wähle eine Bewerbung aus", min_values=1, max_values=1, options=options, custom_id="apply_select:select", # Change to f"apply_select:{self.view_id}" ) async def callback( self, select: discord.ui.Select, interaction: discord.Interaction ): selected_option = select.values[0] user_id = interaction.user.id async with aiosqlite.connect("database/userdata.db") as db: await db.execute( """INSERT INTO users (user_id, option_selected) VALUES (?, ?)""", (user_id, selected_option) ) await db.commit() embed_class = None if selected_option == "Staff Bewerbung": embed_class = StaffEmbed(self.bot) elif selected_option == "Player Bewerbung": embed_class = PlayerEmbed(self.bot) elif selected_option == "Studio Bewerbung": embed_class = StudioEmbed(self.bot) elif selected_option == "Content Creator Bewerbung": embed_class = CCEmbed(self.bot) if embed_class is not None: dm_message = embed_class.create() else: dm_message = "Ungültige Auswahl" try: await interaction.user.send(dm_message) await interaction.response.send_message( f"Die {selected_option} hat begonnen! Schau in deine DM's", ephemeral=True ) except discord.Forbidden: await interaction.response.send_message( "Ich kann dir keine Direktnachricht senden.", ephemeral=True ) await interaction.message.edit(view=self) def setup(bot): bot.add_cog(ApplicationSystem(bot))