discorddiscord.pyticket-system

Discord.py Button


I recently wanted to make an Ticket Bot. It worked but now for no Reason It won't work. I am not the Best in Programing and Typing so please don't judge me on it!

Heres the Code:

class ticket_info(discord.ui.View):
    def __init__(self):
      super().__init__(timeout=None)
  
    @discord.ui.button(label="Close",style=discord.ButtonStyle.blurple, emoji="<:locked:1158126357570650224>", custom_id="ticket_close")
    async def Verifybutton(self,interaction:discord.Interaction,button:discord.ui.Button):
        await interaction.response.send_message("Closing Ticket", ephemeral=True)
        await interaction.channel.delete()

class ticket_embed_(discord.ui.View):
    def __init__(self):
      super().__init__(timeout=None)
  
    @discord.ui.button(label="Open Ticket",style=discord.ButtonStyle.blurple, emoji="<:ticket_:1158126385299210351>", custom_id="ticket_open")
    async def Ticket_Embed_button(self, ctx, interaction:discord.Interaction,button:discord.ui.Button):
          category = discord.utils.get(ctx.guild.categories, name='Support')
          ticket_channel = await category.create_text_channel(f'ticket-{interaction.user.name}')
          await ticket_channel.set_permissions(interaction.user, read_messages=True, send_messages=True)
          await ticket_channel.set_permissions(interaction.guild.default_role, read_messages=False)
          await interaction.response.send_message(f"{interaction.user.mention}, your ticket has been created in {ticket_channel.mention}", ephemeral=True)
          view= ticket_info()
          info = discord.Embed(title=f"Welcome", description="Please State Your issue by using the Format down below:", color=0x476EAA)
          info.add_field(name=" ", value="Your Username:", inline=False)
          info.add_field(name=" ", value="The Issue:", inline=False)
          info.set_footer(text="Seshi - Enhance Your Sessions", icon_url="https://cdn.discordapp.com/attachments/1154789399217852487/1158113442515914833/Seshi-S-wbackground.png?ex=651b10b1&is=6519bf31&hm=c85012ff3b35024f6e44bff045dcd7cbe3f51ca7385b99cecc2459bd64973027&")

          await ctx.send(f'{ctx.author.mention}, your ticket has been created in {ticket_channel.mention}', ephemeral=True)
          await ticket_channel.send(embed=info, view=view)


@client.hybrid_command()
async def create_ticket_embed(ctx):
  view= ticket_embed_()
  channel = client.get_channel(1155249308430504037)
  ticket_embed = discord.Embed(title="Seshi Support", description="Here at Seshi we Respect and help each other thats why you can always open a Ticket in our Server!")
  ticket_embed.set_image(url="https://cdn.discordapp.com/attachments/1154789399217852487/1158172703765827764/Seshi-Enhance-banner.png?ex=651b47e2&is=6519f662&hm=15a183764cba338a4f47be40737599b77d4829c4c6349281e25e162936b72592&")
  ticket_embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/1154789399217852487/1158133155824414760/Seshi-S.png?ex=651b230d&is=6519d18d&hm=a17c1f3cdef1e91d1308e00d7785c39556a45457cbd0d28fed7925ea4f1f2331&")
  ticket_embed.add_field(name='To Create a ticket press the "<:ticket_:1158126385299210351> Open Ticket" Button!', value=" ")
  await channel.send(embed=ticket_embed, view=view)
  await ctx.send("embed sent succesfully!")
  

And Heres the Error:

2023-10-01 23:00:10 ERROR    discord.ui.view Ignoring exception in view <ticket_embed_ timeout=None children=1> for item <Button style=<ButtonStyle.primary: 1> url=None disabled=False label='Open Ticket' emoji=<PartialEmoji animated=False name='ticket_' id=1158126385299210351> row=None>
Traceback (most recent call last):
  File "/home/runner/Another-Seshi-Support-bot/.pythonlibs/lib/python3.10/site-packages/discord/ui/view.py", line 427, in _scheduled_task
    await item.callback(interaction)
  File "/home/runner/Another-Seshi-Support-bot/.pythonlibs/lib/python3.10/site-packages/discord/ui/view.py", line 138, in __call__
    return self.callback(self.view, interaction, self.item)
TypeError: ticket_embed_.Ticket_Embed_button() missing 1 required positional argument: 'button'

I want when the Button is Clicked the bot Creates an Ticket.


Solution

  • The button callback does not take the argument ctx.

    Simply,

    @discord.ui.button(label="Open Ticket",style=discord.ButtonStyle.blurple, emoji="<:ticket_:1158126385299210351>", custom_id="ticket_open")
    async def Ticket_Embed_button(self, interaction: discord.Interaction, button: discord.ui.Button):
        …