I recently received help with my ticket system. Here a ticket is created on reaction. Here, if there is still a ticket open for the user, the bot should output that a ticket has already been created when the reaction is pressed again. However, "You have already created a ticket" appears over and over again, even though I never created a ticket before. I then checked the command I use to create the reaction message and noticed that something was missing in the last row. This looks like the following:
self.enable_reactions(ticket_msg.id, str(reaction[0].emoji))
However, reactor_id is missing here and therefore processes are also not completely executed by the bot, like this following message, which is then displayed as an empty embed:
except:
error_embed = discord.Embed(
desciption="Oops! Something went wrong during finishing the setup process! Please try again!",
color=self.bot.color)
error_embed.timestamp = datetime.datetime.utcnow()
await ctx.send(embed=error_embed)
else:
finished_embed = discord.Embed(
description="Perfect! If everything worked, you can see the message in the designated channel.",
color=self.bot.color)
await ctx.send(embed=finished_embed)
These lines of code appear after self.enable_reactions. I guess this is also related to the fact that no tickets are created and the error message You already have a ticket appears.
My attempt to fix this was to define reactor_id, but I don't get anywhere there because it's an entry in the database.
To create a ticket I have defined the following things:
def enable_reactions(self, message_id: int, reaction: str, reactor_id: int):
cursor = reaction_conn.cursor()
cursor.execute(
'CREATE TABLE IF NOT EXISTS ticket_messages ("message_id" INT, "reaction" TEXT, "reactor_id" INT)')
cursor.execute('INSERT INTO ticket_messages(message_id, reaction, reactor_id) VALUES (?, ?, ? )',
(message_id, reaction, reactor_id))
cursor.close()
reaction_conn.commit()
log.debug(f'Ticket per reaction created for message ID {message_id}')
And then to finally create a ticket a @commands.Cog.listener() with:
cursor = reaction_conn.cursor()
cursor.execute(
'CREATE TABLE IF NOT EXISTS ticket_messages ("message_id" INT, "reaction" TEXT, "reactor_id" INT)')
cursor.execute('SELECT reaction FROM ticket_messages WHERE reactor_id = ?', (payload.user_id,))
row = cursor.fetchone()
cursor.close()
reaction_conn.commit()
if row is not None and row[0] == str(payload.emoji):
await self.createTicket(guild, user, None, f "Created via reaction.") # update this to add user_data
channel = self.bot.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
await message.remove_reaction(payload.emoji, guild.get_member(payload.user_id))
else:
channel3 = self.bot.get_channel(812711563261247518)
await channel3.send("You already have a ticket.") # ctx.send will not work