class CreateSelect(discord.ui.View): open_tickets = 0 def __init__(self): super().__init__(timeout=None) #the drop down menus @discord.ui.select( custom_id="ticketopen", options=[ discord.SelectOption(label="Option 1", description="Description for Option 1", emoji="🎫"), discord.SelectOption(label="Option 2", description="Description for Option 2", emoji="🎫"), discord.SelectOption(label="Option 3", description="Description for Option 3", emoji="🎫"), discord.SelectOption(label="Option 4", description="Description for Option 4", emoji="🎫"), discord.SelectOption(label="Option 5", description="Description for Option 5", emoji="🎫"), discord.SelectOption(label="Option 6", description="Description for Option 6", emoji="🎫"), ], ) async def on_ticket_select(self, interaction: discord.Interaction, select: discord.ui.Select): user_id = interaction.user.id # Check if the user is blacklisted (either in roles or users blacklist) if user_id in blacklisted["users"] or any(role.id in blacklisted["roles"] for role in interaction.user.roles): await interaction.response.send_message("BLACKLIST", ephemeral=True) return # Check if there are already 50 open tickets if self.open_tickets >= 1: await interaction.response.send_message("50 tickets are already open!", ephemeral=True) else: # Handle the ticket creation logic here if select.values[0] == "Option 1": await self.create_ticket(interaction) elif select.values[0] == "Option 2": await self.create_ticket(interaction) elif select.values[0] == "Option 3": await self.create_ticket(interaction) elif select.values[0] == "Option 4": await self.create_ticket(interaction) elif select.values[0] == "Option 5": await self.create_ticket(interaction) elif select.values[0] == "Option 6": await self.create_ticket(interaction) #line 117... change the tickets topic async def create_ticket(self, interaction: discord.Interaction): self.open_tickets += 1 await interaction.response.defer(ephemeral=True) category: discord.CategoryChannel = discord.utils.get(interaction.guild.categories, id=TICKET_CATEGORY_ID) #the category id where the tickets will be made for ch in category.text_channels: if ch.topic == f"{interaction.user.id} DO NOT CHANGE THE TOPIC OF THIS CHANNEL!": await interaction.followup.send("You already have a ticket in {0}".format(ch.mention), ephemeral=True) return r1: discord.Role = interaction.guild.get_role(STAFF_ROLE_ID) #enter the staff role overwrites = { interaction.guild.default_role: discord.PermissionOverwrite(read_messages=False), r1: discord.PermissionOverwrite(read_messages=True, send_messages=True, manage_messages=True), interaction.user: discord.PermissionOverwrite(read_messages=True, send_messages=True), interaction.guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True) } channel = await category.create_text_channel( name=str(interaction.user), topic=f"{interaction.user.id} DO NOT CHANGE THE TOPIC OF THIS CHANNEL!", overwrites=overwrites ) await channel.send( f"**Nice to meet you {interaction.user.mention}|<@&{SERVICE_AGENTS}>**", embed=discord.Embed( title="Ticket Created!", description="> We're pleased to assist you! But let's work together; \n> all we ask is that you provide us as much information \n> so that we can help right away. \n \n ```Multilingual service:``` \n \n 🇹🇭|🇮🇹|🇹🇷|🇬🇧|🇮🇳|🇪🇸|🇻🇳|🇱🇰|🇰🇷|🇵🇰|🇩🇪", color=discord.Color.green() ), view=CloseButton() ) await interaction.followup.send( embed=discord.Embed( description="Created your ticket in {0}".format(channel.mention), color=discord.Color.blurple() ), ephemeral=True ) await send_log( title="Ticket Created", description="Created by {0}".format(interaction.user.mention), color=discord.Color.green(), guild=interaction.guild ) #ratings class ratings(View): def __init__(self): super().__init__(timeout=None) async def send_blacklist_message(self, interaction: discord.Interaction): await interaction.response.send_message("BLACKLIST", ephemeral=True) @button(label='⭐', style=discord.ButtonStyle.red, custom_id='persistent_view:red_rating') async def one_star(self, interaction: discord.Interaction, button: Button): user_id = interaction.user.id # Check if the user is blacklisted (either in roles or users blacklist) if user_id in blacklisted["users"] or any(role.id in blacklisted["roles"] for role in interaction.user.roles): await self.send_blacklist_message(interaction) else: await interaction.response.edit_message(content="⭐ Review!", embed=None, view=None) @button(label='⭐', style=discord.ButtonStyle.blurple, custom_id='persistent_view:blurple_rating') async def two_star(self, interaction: discord.Interaction, button: Button): user_id = interaction.user.id # Check if the user is blacklisted (either in roles or users blacklist) if user_id in blacklisted["users"] or any(role.id in blacklisted["roles"] for role in interaction.user.roles): await self.send_blacklist_message(interaction) else: await interaction.response.edit_message(content="⭐⭐ Review!", embed=None, view=None) @button(label='⭐', style=discord.ButtonStyle.grey, custom_id='persistent_view:grey_rating') async def three_star(self, interaction: discord.Interaction, button: Button): user_id = interaction.user.id # Check if the user is blacklisted (either in roles or users blacklist) if user_id in blacklisted["users"] or any(role.id in blacklisted["roles"] for role in interaction.user.roles): await self.send_blacklist_message(interaction) else: await interaction.response.edit_message(content="⭐⭐⭐ Review!", embed=None, view=None) @button(label='⭐', style=discord.ButtonStyle.green, custom_id='persistent_view:green_rating') async def four_star(self, interaction: discord.Interaction, button: Button): user_id = interaction.user.id # Check if the user is blacklisted (either in roles or users blacklist) if user_id in blacklisted["users"] or any(role.id in blacklisted["roles"] for role in interaction.user.roles): await self.send_blacklist_message(interaction) else: await interaction.response.edit_message(content="⭐⭐⭐⭐ Review!", embed=None, view=None) @button(label='⭐', style=discord.ButtonStyle.green, custom_id='persistent_view:green_rating_star') async def five_star(self, interaction: discord.Interaction, button: Button): user_id = interaction.user.id # Check if the user is blacklisted (either in roles or users blacklist) if user_id in blacklisted["users"] or any(role.id in blacklisted["roles"] for role in interaction.user.roles): await self.send_blacklist_message(interaction) else: await interaction.response.edit_message(content="⭐⭐⭐⭐⭐ Review!", embed=None, view=None) #close button class CloseButton(View): def __init__(self): super().__init__(timeout=None) async def send_blacklist_message(self, interaction: discord.Interaction): await interaction.response.send_message("BLACKLIST", ephemeral=True) @button(label="Close the ticket", style=discord.ButtonStyle.red, custom_id="closeticket", emoji="🔒") async def close(self, interaction: discord.Interaction, button: Button): user_id = interaction.user.id # Check if the user is blacklisted (either in roles or users blacklist) if user_id in blacklisted["users"] or any(role.id in blacklisted["roles"] for role in interaction.user.roles): await self.send_blacklist_message(interaction) else: embed = discord.Embed(description="Please give us a review") await interaction.channel.send(embed=embed, view=ratings()) await interaction.response.defer(ephemeral=True) # await interaction.channel.send("Closing this ticket in 3 seconds! (delte this message from line 191, make sure to edit the line exactly below this message as well)", ephemeral = True) await asyncio.sleep(3) category: discord.CategoryChannel = discord.utils.get(interaction.guild.categories, id=CLOSED_TICKET_CATEGORY_ID) # Only allow the ticket opener to see the channel and not send messages opener_member = interaction.guild.get_member(int(interaction.channel.topic.split(" ")[0])) overwrites = { opener_member: discord.PermissionOverwrite(read_messages=True, send_messages=False), interaction.guild.default_role: discord.PermissionOverwrite(read_messages=False), interaction.guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True) } # Move the ticket channel back to the original category and update overwrites await interaction.channel.edit(category=category, overwrites=overwrites) # Send a confirmation message that the ticket is closed and provide a TrashButton view await interaction.channel.send( embed=discord.Embed(description="Ticket Closed!", color=discord.Color.red()), view=TrashButton() ) # Get the member associated with the ticket and retrieve the transcript of the ticket member = opener_member await get_transcript(member=member, channel=interaction.channel) # Extract information from the transcript file name and send a log message folder_name = "ticket-log" file_name = await get_transcript(member=member, channel=interaction.channel) file_parts = os.path.basename(file_name).split("_") if len(file_parts) == 2: member_id = file_parts[0] timestamp_str = file_parts[1].split(".")[0] timestamp = datetime.strptime(timestamp_str, "%Y%m%d%H%M%S") timestamp = timestamp.strftime("%Y-%m-%d %H:%M:%S") link = f"https://03a4b61f8918-8217440807003319771.ngrok-free.app/ticket-logs/{os.path.basename(file_name)}" await send_log( title="Ticket Closed", description=f"Closed by: {interaction.user.mention}\nTicket ID: {member_id}\nTimestamp: {timestamp}\n[click for transcript]({link})", color=discord.Color.yellow(), guild=interaction.guild ) class TrashButton(View): def __init__(self): super().__init__(timeout=None) async def send_blacklist_message(self, interaction: discord.Interaction): await interaction.response.send_message("BLACKLIST", ephemeral=True) @button(label="Delete the ticket", style=discord.ButtonStyle.red, emoji="🚮", custom_id="trash") async def trash(self, interaction: discord.Interaction, button: Button): user_id = interaction.user.id # Check if the user is blacklisted (either in roles or users blacklist) if user_id in blacklisted["users"] or any(role.id in blacklisted["roles"] for role in interaction.user.roles): await self.send_blacklist_message(interaction) else: print("Trash button clicked.") # Debug statement to check if the trash function is called await interaction.response.defer() # the timer.. make it 0 if u want instant closing await interaction.channel.send("Deleting the ticket in 3 seconds") await asyncio.sleep(3) await interaction.channel.delete() await send_log( title="Ticket Deleted", description=f"Deleted by {interaction.user.mention}, ticket: {interaction.channel.name}", color=discord.Color.red(), guild=interaction.guild ) open_tickets -= 1