title: How can I make a custom decorator out of my SQL database?
body: <p>I am creating a ticket system and defined various sub-commands. These should only be executable when the user is in his own channel. However, the user can still enter <code>!trivia subcommand</code> and it will do just that. Is there a check to stop this so the user can only execute the command in his own channel, but nowhere else? I work with a database, would I have to determine the text channel and check whether this command was also executed there?</p>
  <p>I have introduced a <code>!trivia close</code> command, but I can't use that here because the <code>table</code> would be dropped as well. That's not supposed to happen, because after the certain command <code>!trivia start</code> an event is triggered.</p>
  <p>My code for the <code>close</code> command:</p>
  <pre><code>try:
      guild = self.bot.get_guild(id=ctx.guild.id)
      ticketChannel = guild.get_channel(int(ctx.channel.id))
      fetchOne('closed', ctx.channel.id)
      e.description = f'{ticketChannel.mention} is closed!'
      await ctx.send(embed=e)
      await ticketChannel.delete(reason=f'{ctx.author.name} close the ticked!')
  
      main = sqlite3.connect('src/ticket.db')
      cur = main.cursor()
      cur.execute(f'DROP TABLE `{ctx.channel.id}`')
      cur.close()
      main.commit()
      main.close()
  except Exception as err:
      print(err)
      e.title = 'Ticket not found! Please use this command in a ticket channel!'
      await ctx.send(embed=e, delete_after=3)
  </code></pre>
  <p>How I create a ticket in general:</p>
  <pre><code>async def trivia_ticket(self, guild, author, channel, info):
      cursor = conn.cursor()
      try:
          data = fetchOne('category', guild.id)
      except sqlite3.OperationalError:
          cursor.execute(f&quot;CREATE TABLE IF NOT EXISTS `{guild.id}`('category' INT, 'channel_id' INT)&quot;)
          cursor.execute(f'INSERT INTO `{guild.id}`(category) VALUES (&quot;{None}&quot;)')
          conn.commit()
          data = fetchOne('category', guild.id)
      e = discord.Embed(color=self.bot.color)
      overwrites = {
          guild.default_role: discord.PermissionOverwrite(read_messages=False),
          author: discord.PermissionOverwrite(read_messages=True),
          guild.me: discord.PermissionOverwrite(read_messages=True)
      }
      if data[0] == &quot;None&quot;:
          trivia_channel = await guild.create_text_channel(name=f'{author.name}-ticket', overwrites=overwrites,
                                                           topic=f'Owner: {author.id}, Info: Please follow the rules')
          ec = discord.Embed(color=self.bot.color)
          ec.title = &quot;Welcome to your own channel!&quot;
          ec.description = &quot;To start just type `!trivia start` into the channel.&quot;
          ec.add_field(name=&quot;How long do I have to answer the question?&quot;, value=&quot;30 seconds to set a reaction&quot;)
          ec.add_field(name=&quot;How can I stop the quiz?&quot;,
                       value=&quot;After every question you can take a break, you will be &quot;
                             &quot;asked. `!stop` will delete the channel and you have to &quot;
                             &quot;wait for the next quiz&quot;, inline=False)
          await trivia_channel.send(embed=ec)
      else:
          category = guild.get_channel(int(data[0]))
          trivia_channel = await guild.create_text_channel(name=f'{author.name}-ticket', overwrites=overwrites,
                                                           topic=f'Owner: {author.id}, Info: Please follow the rules!',
                                                           category=category)
          ec = discord.Embed(color=self.bot.color)
          ec.title = &quot;Welcome to your own channel!&quot;
          ec.description = &quot;To start just type `!trivia start` into the channel.&quot;
          ec.add_field(name=&quot;How long do I have to answer the question?&quot;, value=&quot;30 seconds to set a reaction&quot;)
          ec.add_field(name=&quot;How can I stop the quiz?&quot;,
                       value=&quot;After every question you can take a break, you will be &quot;
                             &quot;asked. `!stop` will delete the channel and you have to &quot;
                             &quot;wait for the next quiz&quot;, inline=False)
          await trivia_channel.send(embed=ec)
      e.title = f&quot;Success! Your trivia ticket has been created here:&quot;
      e.description = f'{trivia_channel.mention}'
      if channel is not None:
          await channel.send(embed=e, delete_after=3)
      cursor.execute(f'CREATE TABLE IF NOT EXISTS `{trivia_channel.id}`(&quot;author_name&quot; TEXT, &quot;author_id&quot; INT, '
                     f'&quot;info&quot; TEXT, &quot;channel_name&quot; TEXT, &quot;closed&quot; BOOL)')
      cursor.execute(f'INSERT INTO `{trivia_channel.id}`(author_name, author_id, info, channel_name, closed) VALUES(?, ?, ?, ?, &quot;{False}&quot;)', (author.name, author.id, str(info), str(trivia_channel)))
      cursor.close()
      conn.commit()
  </code></pre>
  <p>The <code>Ticket not found</code> output should be seen if the user tries to run the command in any other channel but not his own.</p>
  <p>My command (<code>!trivia start</code>) which should only be executed in the own channel (and in no other channel including the group):</p>
  <pre><code>@commands.group(invoke_without_command=True, name='trivia', case_insensitive=False)
  @commands.guild_only()
  @commands.cooldown(1, 10, BucketType.user)
  async def trivia_channel(self, ctx, Information: str=&quot;Please follow the rules.&quot;):
      &quot;&quot;&quot;Creates a trivia channel for the user.&quot;&quot;&quot;
      try:
          await self.trivia_ticket(ctx.guild, ctx.author, ctx.channel, Information)
      except Exception as e:
          print(f'ERROR: {e}')
          return
  
  @trivia_channel.command(aliases=[&quot;testing&quot;])
  @commands.guild_only()
  async def start(self, ctx):
      &quot;&quot;&quot;Starts the trivia quiz.&quot;&quot;&quot;
  </code></pre>
  <p>I have a workaround to prevent people from spamming <code>!trivia start</code> (which would be <code>@commands.cooldown(1, 10, BucketType.user)</code>). I also tried to make the command accessible by role, but that is not wanted. I want to built a custom decorator which checks the stored channel ID and the channel ID the command was executed in. If it returns <code>False</code> I do not want the command to be executed.</p>