1

I am creating a ticket system for my bot so that members can tell their issue to mods and I can create multiple ticket channels without any limit by reacting again and again. But I want that there should be a limit so that when there is an ongoing ticket so that a specific user cannot create one more ticket and the bot should yell at him.

Code:

 @bot.event
 async def on_raw_reaction_add(payload):
    if payload.member.id != bot.user.id and str(payload.emoji)== u"\U0001F3AB":
        msg_id, channel_id, category_id= bot.ticket_configs[payload.guild_id]

        if payload.message_id == msg_id:
            guild= bot.get_guild(payload.guild_id)
  
            for category in guild.categories:
                if category.id == category_id:
                    break
   
            channel = guild.get_channel(channel_id)

            ticket_num= 1 if len(category.channels) == 0 else int(category.channels[-1].name.split("-")[1]) + 1
            ticket_channel= await category.create_text_channel(f"Ticket {ticket_num}", topic= f"Channel for ticket number {ticket_num}.", permission_synced= True)
    
            await ticket_channel.set_permissions(payload.member, read_messages= True, send_messages= True) 
    
            message= await channel.fetch_message(msg_id)
            await message.remove_reaction(payload.emoji, payload.member)
    
            await ticket_channel.send(f"{payload.member.mention} Thank You! for creating this ticket staff will contact you soon. Type **-close** to close the ticket.")
    
            try:
                await bot.wait_for("message", check=lambda m: m.channel== ticket_channel and m.author== payload.member and m.content == "-close", timeout= 3600)
                
            except asyncio.TimeoutError:
                await ticket_channel.delete()
    
            else:
                await ticket_channel.delete()

TL;DR: My bot can currently create multiple ticket channels without any limits. However, I want to enforce a limit where if a user had an existing ticket but started a new channel, the bot would remind him that he already has an existing ticket.

PerplexingParadox
  • 1,196
  • 1
  • 7
  • 26
IDK
  • 131
  • 1
  • 11

1 Answers1

1

try this

if discord.utils.get(guild.channels, name=f"Ticket {ticket_num}") != None:
    await payload.member.send(content=f"Ticket {ticket_num} is already an existing channel!")
ShadMilkGod
  • 53
  • 1
  • 8