Harjot
Harjot

Reputation: 943

How to make a channel delete reaction in discord.py(rewrite)?

So, I made a command !vx new which creates a new channel with all the permissions of the author and admins set up, in a certain category. Now I want to create a command which deletes the ticket - !vx close. This was the code I figured out,it works but the problem with this is that it can receive "Yes" from any of the user in the ticket.

@client.command(name='close', aliases=['delete'])
@commands.has_permissions(administrator=True)
async def close(ctx):
    await ctx.send("Do you want to delete this channel?")

    @commands.Cog.listener()
    async def on_reaction_add(self, reaction, user: discord.Member):

        def check(reaction, user):
            name_list = []
            for emoji in reaction.message.reactions:
                name_list.append(emoji.emoji)

            return '✅' in name_list and reaction.message.author.id == MyBotID and reaction.message.content == "Do you want to delete this channel?" and user.guild_permissions.administrator

        if check(reaction, user):
            await ctx.send("K!")
            await ctx.channel.delete()

I want the user who types !vx close to react with a cross/tick mark which will close the ticket if the author reacts with tick and will not close if the author reacts with cross.

EDIT - The above code is also not working.

Upvotes: 2

Views: 875

Answers (1)

Kelo
Kelo

Reputation: 1893

You can get the Member object from the function's Context (ctx) and the message from the client.wait_for(). So you can have the check function be:

return m.content.lower() == 'yes' and ctx.message.author == m.author

For the emoji bit, you can put a if statement inside the on_reaction_add event to say something along the lines of "if message by me (the bot) AND message content is for a close AND reaction emoji is agree AND user has permissions 'administrator' "

Emoji Code as requested: It would look something like this.

    @commands.Cog.listener()
    async def on_reaction_add(self, reaction, user : discord.Member):

        def check(reaction, user):
            name_list = []
            for emoji in reaction.message.reactions:
                name_list.append(emoji.emoji)

            return '✅' in name_list and reaction.message.author.id == yourBotsID and reaction.message.content == "Do you want to delete this channel?" and user.guild_permissions.administrator

        if check(reaction, user):
            await ctx.send("K!")
            await ctx.channel.delete()

Upvotes: 2

Related Questions