Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Discord Python Bot nuke command partially works

$
0
0

So I've tried to make my discord bot a nuke command, but only the nuke part works, the cancel part doesn't work.

My code:

import discordfrom discord.ext import commandsfrom discord.ui import Button, Viewclass Channels(commands.Cog):    def __init__(self, bot):        self.bot = bot    @commands.command()    @commands.has_permissions(manage_channels=True)    async def nuke(self, ctx, channel: discord.TextChannel = None):        if channel is None:             await ctx.send(f"{ctx.author.mention}! You did not mention a channel!", delete_after=5)            return        nuke_channel = discord.utils.get(ctx.guild.channels, name=channel.name)        if nuke_channel is not None:            yes = Button(label="Yes", style=discord.ButtonStyle.green)            no = Button(label="No", style=discord.ButtonStyle.red)            async def yes_callback(interaction):                if interaction.user == ctx.author:                    new_channel = await nuke_channel.clone(reason="Has been Nuked!")                    await nuke_channel.delete()                    await new_channel.send(f"Nuked! {ctx.author.mention}", delete_after=0.1)                    await new_channel.send(f"Nuked by `{ctx.author.name}`")                    with open("logs.json", "a") as f:                        f.writelines(f"\n{ctx.author} used the nuke command. Channel nuked: {nuke_channel.name}")            async def no_callback(interaction):                if interaction.user == ctx.author:                    await nuke_channel.send("Aborted")                    no.label = "No more pressing!"                     no.disabled = True                      await interaction.response.edit_message(view=self)            yes.callback = yes_callback            no.callback = no_callback            view = View()            view.add_item(yes)            view.add_item(no)            await nuke_channel.send(f"{ctx.author.mention}, are you sure you want to nuke this channel?", view=view)        else:            await ctx.send(f"No channel named **{channel.name}** was found!")    @nuke.error    async def nuke_error(self, ctx, error):        if isinstance(error, commands.MissingPermissions):            await ctx.send("You don't have permission to use this command.")

When I click yes, everything goes fine. But when I click no, the bot send a message "Aborted" and displays interaction failed But then the buttons are still clickable. My question is, how to make the buttons unclickable after pressing no, and how to stop making it show interaction failed. Cuz like I already have added no.disabled = True so I've got no idea whats wrong


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>