I am creating ticket tool for my discord bot but a user can create unlimited tickets by reacting there. However, I want the bot to dm that user to remind them that he is already having an open ticket.
This is what I have tried so far but it didn't work at all:
guild = await bot.fetch_guild(id)
channels = guild.text_channels
duplicate = False
name = f"{payload.member.name}'s ticket"
for channel in channels:
if name == channel.name:
duplicate = True
break
if duplicate:
await payload.member.send("You already have an open ticket")
return
else:
await category.create_text_channel(name, topic= topic, permission_synced= True)
await ticket_channel.set_permissions(payload.member, read_messages= True, send_messages= True)
Text channels cannot have spaces nor quotation marks in their names (it will also be converted to lowercase), a name like this Name's ticket will be converted to names-tickets.
name = f"{payload.member.name.lower()}s-ticket"
for channel in channels:
if name == channel.name:
duplicate = True
break
You can also simplify the code a lot, instead of having the for-loop you can use the any function
duplicate = any(name == channel.name for channel in channels)
if duplicate:
return await payload.member.send("You already have an open ticket")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With