-4

sorry that this is probably rather easy to fix (I don't really understand the docs) But, I want a channel to be opened, so only the user and mods can see it. It will be opened when the user adds a reaction to the message, the reaction will then be deleted (leaving just the bot's reaction) Currently, my code is:

    @commands.Cog.listener()
    async def on_reaction_add(self, reaction, user):
        if reaction.emoji == '':
            if user.channel.id == 850622999577231370:
                await message.remove_reaction("", user)
                overwrites = {
                    guild.default_role: discord.PermissionOverwrite(read_messages=False),
                    guild.me: discord.PermissionOverwrite(read_messages=True)
                }
                n = random.randomint(1, 1000)
                await guild.create_text_channel(f'Ticket {n}', overwrites=overwrites, categoty="Tickets")
            else:
                pass
        else:
            pass

It doesn't seem to run, since there is no error message, but no channels are created either

Mdog504
  • 37
  • 1
  • 7

1 Answers1

0

A few things I noticed:

  • random.randomint does not exist, it must be random.randrange.
  • You didn't define guild in the provided code, we'll just use user.guild instead.
  • To get the channel we use if reaction.message.channel.id and not if user.channel.id, that makes little sense here.

Here is a possible new code:

@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
    if reaction.emoji == '':
        print("Reaction")
        if reaction.message.channel.id == Your_Channel_ID:
            await reaction.message.remove_reaction("", user)
            guild = user.guild # We get the guild
            overwrites = {
                guild.default_role: discord.PermissionOverwrite(read_messages=False),
                guild.me: discord.PermissionOverwrite(read_messages=True)
            }
            n = random.randrange(1, 1000) # We choose a number from randrange 1-1000
            await guild.create_text_channel(f'Ticket {n}', overwrites=overwrites, categoty="Tickets")
        else:
            pass
    else:
        pass
Dominik
  • 3,612
  • 2
  • 11
  • 44
  • Great, I’ll look at it when I’m next working. Randomint was defined earlier by importing something, but I prefer your way – Mdog504 Aug 03 '21 at 18:54