【问题标题】:Is there anyway to have a two step command in discord.py无论如何在discord.py中有一个两步命令
【发布时间】:2021-04-02 15:11:21
【问题描述】:

我有这个:

       @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!')

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

【问题讨论】:

  • 你的方法是什么? “为我实现此功能”与 StackOverflow 无关

标签: python discord discord.py 12factor


【解决方案1】:

您可以使用 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

【讨论】:

  • 我添加了这个:if response.content == 'yes': await ctx.send("Done") else: await ctx.send("Cancelled") 当我运行它时没有任何反应。
  • 该命令对我有用。这可能是缩进问题或因为输入区分大小写。将response.content 编辑为response.content.lower() 以解决区分大小写的问题。您可能还想重新检查缩进。
  • 我检查了缩进并添加了response.content.lower(),但当我回答是时仍然没有任何反应。
  • 没什么,只是不会发送消息'Done'
  • 我不知道问题的根源... 作为最后的手段,从 cog 中取出命令,进行必要的编辑并尝试一下。如果它不起作用,您的代码可能被阻止了。
猜你喜欢
  • 2021-06-01
  • 2020-10-09
  • 2021-10-21
  • 2021-09-19
  • 2022-10-07
  • 2021-02-22
  • 1970-01-01
  • 2018-10-02
  • 1970-01-01
相关资源
最近更新 更多