Anfang Ticket

This commit is contained in:
Soenke committed 2026-07-18 22:08:11 +02:00
1 parent ec2bbf406c
commit 150c36da28
3 files changed
+157 -1

No files matched your search

+5
View File
@@ -6,6 +6,11 @@ GUILD_ID=
JOIN_LEAVE_CHANNEL_ID=
CREATE_TICKET_CHANNEL_ID=
TICKET_LOGS_CHANNEL_ID=
TICKET_UNCLAIMED_CATEGORY_ID=
TICKET_CLAIMED_CATEGORY_ID=
CREATE_MEETUP_CHANNEL_ID=
DE_MEETUP_CHANNEL_ID=
AT_MEETUP_CHANNEL_ID=
+152
View File
@@ -0,0 +1,152 @@
import os
import discord
from discord.ext import commands, tasks
from dotenv import load_dotenv
load_dotenv()
async def CreateTicketChannel(interaction: discord.Interaction, chosen_language):
bot = interaction.client
guild_id = int(os.getenv("GUILD_ID"))
category_id = int(os.getenv("TICKET_UNCLAIMED_CATEGORY_ID"))
guild = bot.get_guild(guild_id)
if not guild:
print("Error: Guild not found. Check your GUILD ID.")
return None
category = guild.get_channel(category_id)
if not category or not isinstance(category, discord.CategoryChannel):
print("Error: Category not found or is not a category channel.")
return None
num = 1
num_str = f"{num:04d}"
emoji = "🇩🇪" if chosen_language == "de" else "🇺🇸"
channel_name = f"{emoji}-ticket-{num_str}"
ticket_channel = await category.create_text_channel(name=channel_name)
return ticket_channel
class CreateDETicketForm(discord.ui.Modal, title="Ticket erstellen"):
def __init__(self, chosen_language: str):
super().__init__()
self.chosen_language = chosen_language
form_location = discord.ui.TextInput(
label="Warum erstellen Sie dieses Ticket?",
style=discord.TextStyle.paragraph,
placeholder="",
required=True,
max_length=400
)
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
ticket_channel = await CreateTicketChannel(interaction, self.chosen_language)
if ticket_channel:
await interaction.followup.send(
f"✅ Das Ticket wurde erfolgreich erstellt: {ticket_channel.mention}",
ephemeral=True
)
else:
await interaction.followup.send(
"❌ Fehler beim Erstellen des Tickets. Bitte kontaktiere einen Admin.",
ephemeral=True
)
class CreateENTicketForm(discord.ui.Modal, title="Create a Ticket"):
def __init__(self, chosen_language: str):
super().__init__()
self.chosen_language = chosen_language
form_location = discord.ui.TextInput(
label="Why are you creating this ticket?",
style=discord.TextStyle.paragraph,
placeholder="",
required=True,
max_length=400
)
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
ticket_channel = await CreateTicketChannel(interaction, self.chosen_language)
if ticket_channel:
await interaction.followup.send(
f"✅ The ticket was successfully created: {ticket_channel.mention}",
ephemeral=True
)
else:
await interaction.followup.send(
"❌ Error creating the ticket. Please contact an admin.",
ephemeral=True
)
class LanguageSelect(discord.ui.Select):
def __init__(self):
options = [
discord.SelectOption(label="Deutsch", value="de", emoji="🇩🇪"),
discord.SelectOption(label="English", value="en", emoji="🇺🇸"),
]
super().__init__(placeholder="Sprache auswählen / Select language", min_values=1, max_values=1, options=options)
async def callback(self, interaction: discord.Interaction):
if self.values[0] == "de":
await interaction.response.send_modal(CreateDETicketForm(chosen_language=self.values[0]))
else:
await interaction.response.send_modal(CreateENTicketForm(chosen_language=self.values[0]))
await interaction.delete_original_response()
class LanguageDropdownView(discord.ui.View):
def __init__(self):
super().__init__(timeout=60)
self.add_item(LanguageSelect())
class MainInteractiveMenu(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(label="📩 Create ticket", style=discord.ButtonStyle.blurple)
async def primary_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message(
content="Bitte wählen Sie Ihre Sprache aus, um fortzufahren:\nPlease select your language to continue:",
view=LanguageDropdownView(),
ephemeral=True
)
class Ticket(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def cog_load(self):
self.startup.start()
def cog_unload(self):
self.startup.cancel()
@tasks.loop(count=1)
async def startup(self):
await self.bot.wait_until_ready()
channel = await self.bot.fetch_channel(os.getenv("CREATE_TICKET_CHANNEL_ID"))
await channel.purge(limit=None, bulk=True)
await channel.send("""
# Support
Um ein Ticket zu erstellen, reagieren Sie mit 📩
To create a ticket react with 📩
""", view=MainInteractiveMenu())
async def setup(bot):
await bot.add_cog(Ticket(bot))
-1
View File
@@ -29,7 +29,6 @@ class JoinLeave(commands.Cog):
@commands.Cog.listener()
async def on_member_remove(self, member):
if member.guild.id != int(os.getenv("GUILD_ID")):
print("NOT GUILD")
return
channel = member.guild.get_channel(int(os.getenv("JOIN_LEAVE_CHANNEL_ID")))