I'm trying to make a bot ticket, but I don't know how to send the button that deletes the channel inside the newly created ticket

33 Views Asked by At

Everything works, but I don't know how to send the message with the button inside the newly created ticket, this is the code:

class SimpleView(discord.ui.View):
    def __init__(self):
         super().__init__(timeout=None)
        
        



    @discord.ui.button(label=" ", style=discord.ButtonStyle.red, custom_id="1")
    async def ticketopen(self, interaction: discord.Interaction, button: discord.ui.Button):
         

         adrole = discord.utils.get(interaction.guild.roles, name="Founder")
         adrole2 = discord.utils.get(interaction.guild.roles, name="Capo")
         adrole3 = discord.utils.get(interaction.guild.roles, name="Gestore")


         # Trova la categoria in cui creare il nuovo canale
         category_id = 1217168877235212358
         category = discord.utils.get(interaction.guild.categories, id=1217168877235212358)

          # Creare permessi per il nuovo canale
         overwrites = {
              
             interaction.guild.default_role: discord.PermissionOverwrite(view_channel=False),  # Impedire a tutti di leggere i messaggi
             interaction.guild.me: discord.PermissionOverwrite(read_messages=True),  # Consentire al bot di leggere i messaggi
             adrole: discord.PermissionOverwrite(view_channel=True, manage_messages=True),
             adrole2: discord.PermissionOverwrite(view_channel=True, manage_messages=True),
             adrole3: discord.PermissionOverwrite(view_channel=True, manage_messages=True),
             interaction.user: discord.PermissionOverwrite(view_channel=True, manage_messages=True)
          }

         # Creare il nuovo canale
         new_channel = await category.create_text_channel(name=f"ticket-{interaction.user.name}", overwrites=overwrites)
         await interaction.response.send_message(f"**Ticket creato con successo!**", ephemeral=True)
         
         channel = bot.get_channel(1222542285464404078)
         role = discord.utils.get(interaction.guild.roles, id=1217907520895713381)
         embed=discord.Embed()
         embed.add_field(name=f"NUOVO TICKET!", value=f"{interaction.user.mention} HA CREATO UN TICKET", inline=True)
         embed.set_footer(text=f"{date_time} ")
         await channel.send(embed=embed)
         await channel.send(f"||{role.mention}||")












         channel = discord.utils.get(interaction.guild.channels, name=f"ticket-{interaction.user.name}")
         embed=discord.Embed()
         embed.set_author(name="PurpleWeed", icon_url="https://shft.cl/img/c/cdn.discordapp.com-103393179143164560.webp")
         embed.add_field(name=" ", value="Usa questo pulsante per chiudere il ticket.", inline=False)

         view = ui.View()
         close_button = ui.button(label=" ", style=discord.ButtonStyle.red, custom_id="1")
         async def ticketclose(self, interaction: discord.Interaction, button: discord.ui.Button):
               
                    allowed_role_id = 1217170449717264555
                    allowed_role_id_2 = 1217170012478115951
                    allowed_role_id_3 = 1217907806083219506
                    allowed_role = discord.utils.get(interaction.guild.roles, id=allowed_role_id)
                    allowed_role2 = discord.utils.get(interaction.guild.roles, id=allowed_role_id_2)
                    allowed_role3 = discord.utils.get(interaction.guild.roles, id=allowed_role_id_3)  



                    if allowed_role is None or allowed_role not in interaction.user.roles:
                         if allowed_role2 is None or allowed_role2 not in interaction.user.roles:
                              if allowed_role3 is None or allowed_role3 not in interaction.user.roles:
                                   await interaction.response.send_message(f"**Non puoi chiudere il ticket, non sei** {allowed_role.mention}**/**{allowed_role2.mention}**/**{allowed_role3.mention}", ephemeral=True)


                    if allowed_role in interaction.user.roles:
                         await channel.delete

         ticketclose.callback = close_button
         view.add_item(item=ticketclose)
         await channel.send(embed=embed, view=view)

The problem starts from: "view = ui.View()" or when I create the button to send. The button is there, but it doesn't send, everything else above works correctly as it should work. I tried looking for different solutions, but they don't work, this is the error it gives me: "TypeError: expected Item not function" Help me please

0

There are 0 best solutions below