[Python] My Discord py-cord interaction doesn't respond with a message

Discussão em 'Python' iniciado por Stack, Março 8, 2025.

  1. Stack

    Stack Membro Participativo

    The await interaction.response.send_message(f"A ticket has been created {ticket_channel.mention}", ephemeral=True) part of the code does not send a message after the interaction.

    import discord
    from discord.ext import commands
    from discord.ui import View, Select
    import asyncio

    intents = discord.Intents.default()
    intents.message_content = True

    bot = commands.Bot(command_prefix="!", intents=intents)

    class TicketDropdown(Select):
    def __init__(self):
    options = [
    discord.SelectOption(label="Issue 1", description="Lorem ipsum", value="issue1"),
    discord.SelectOption(label="Issue 2", description="Lorem ipsum", value="issue2"),
    discord.SelectOption(label="Issue 3", description="Lorem ipsum", value="issue3"),
    ]
    super().__init__(placeholder="Select an issue...", options=options)

    async def callback(self, interaction: discord.Interaction):
    issue = self.values[0]
    user = interaction.user
    category = discord.utils.get(interaction.guild.categories, name="Support Tickets")
    if not category:
    category = await interaction.guild.create_category("Support Tickets")

    ticket_channel = await interaction.guild.create_text_channel(
    f"ticket-{user.name}-{issue}", category=category
    )
    await interaction.response.send_message(f"A ticket has been created {ticket_channel.mention}", ephemeral=True)
    role = discord.utils.get(interaction.guild.roles, name="Moderators")
    await ticket_channel.set_permissions(role, view_channel=True, send_messages=True)
    await ticket_channel.set_permissions(user, view_channel=True, send_messages=True)

    await ticket_channel.send(
    f"**{user.mention}** created a ticket: **{issue}**.\nSend a reason within **15 minutes**, or the ticket will close."
    )

    def check(m):
    return m.channel == ticket_channel and m.author == user

    try:
    message = await bot.wait_for("message", timeout=900, check=check)
    await message.reply("Lorem ipsum")
    except asyncio.TimeoutError:
    await ticket_channel.send("Ticket closed due to inactivity.")
    await ticket_channel.delete()

    class TicketView(View):
    def __init__(self):
    super().__init__()
    self.add_item(TicketDropdown())

    @bot.event
    async def on_ready():
    print(f"Logged in as {bot.user}")

    @bot.event
    async def on_message(message):
    if message.author.bot:
    return

    if message.channel.category and "Support Tickets" in message.channel.category.name:
    await message.reply("Lorem ipsum")

    await bot.process_commands(message)

    @bot.command()
    async def ticket(ctx):
    embed = discord.Embed(title="Create a Support Ticket", description="Lorem ipsum", color=discord.Color.blue())
    await ctx.send(embed=embed, view=TicketView())

    @bot.command()
    async def close(ctx):
    if isinstance(ctx.channel, discord.TextChannel) and ctx.channel.category and "Support Tickets" in ctx.channel.category.name:
    await ctx.send("Closing ticket...")
    await ctx.channel.delete()
    else:
    await ctx.send("This command can only be used in a ticket channel.")



    I tried changing the interaction.response.send_message to interaction.followup.send but to no avail

    Continue reading...

Compartilhe esta Página