#Modal

1 messages · Page 1 of 1 (latest)

fluid mortar
#

I don't know what's wrong with my modal

#

I've nothing in the terminal

round kestrel
#

send your code?

stray meteor
#

i've seen that error several times in the past week or so from different people, weird

fluid mortar
round kestrel
#

yes

fluid mortar
#
import discord
from discord.ext import commands
from command.closeticketview import CloseTicketView

class TicketModal(discord.ui.Modal):
    def __init__(self, bot, category):
        super().__init__(title="Créer un Ticket")
        self.bot = bot
        self.category = category
        self.reason = discord.ui.InputText(
            label="Raison",
            style=discord.InputTextStyle.long,
            placeholder="Veuillez entrer la raison de la création du ticket.",
            required=True,
        )
        self.add_item(self.reason)

    async def on_submit(self, interaction: discord.Interaction):
        print (self.reason.value)
        reason = self.reason.value

        guild = interaction.guild
        category = await guild.fetch_channel(self.category)

        if category and isinstance(category, discord.CategoryChannel):
            overwrites = {
                guild.default_role: discord.PermissionOverwrite(read_messages=False),
                interaction.user: discord.PermissionOverwrite(read_messages=True, send_messages=True),
                guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True),
            }

            ticket_channel = await category.create_text_channel(f'ticket-{interaction.user.display_name}', overwrites=overwrites)
            await ticket_channel.send(f'Ticket créé par {interaction.user.mention} pour la raison suivante : {reason}', view=CloseTicketView(self.bot))

            # Supprimer les messages non bot dans le même salon
            async for msg in interaction.channel.history(limit=100):
                if msg.author != self.bot.user:
                    await msg.delete()

            await interaction.response.send_message(f'Ticket créé : {ticket_channel.mention}', ephemeral=True)
        else:
            print("La catégorie spécifiée n'a pas été trouvée ou n'est pas une catégorie de texte.")
            await interaction.response.send_message("La catégorie spécifiée n'a pas été trouvée ou n'est pas une catégorie de texte.", ephemeral=True)


class TicketView(discord.ui.View):
    def __init__(self, bot, category=None):
        super().__init__(timeout=None)
        self.bot = bot
        self.category = category

    @discord.ui.button(label="Créer un ticket", style=discord.ButtonStyle.green, custom_id="create_ticket")
    async def create_ticket(self, button: discord.ui.Button, interaction: discord.Interaction):
        await interaction.response.send_modal(TicketModal(self.bot, self.category))
#

I'm creating a ticket system

round kestrel
#

should be callback and not on_submit

#

where did you get on_submit from?

fluid mortar
young cosmos
round kestrel
young cosmos
#

yeah but u asked where it could be from kek

round kestrel
#

I'm wondering what source they used to get on_submit for pycord modals since it is rather common issue

fluid mortar