接受基于 discord.py 中第一个输入的第二个输入

问题描述

我希望我的机器人有一个删除频道中所有消息的命令。

@pip.command()
async def clear(ctx,amount):
    if amount == "all":
        await ctx.send("Are you sure you want to delete all messages in this channel?")
        async def yes(ctx):
            if ctx == "yes":
                await ctx.channel.purge(limit=100000000)

这是我的代码

它向我发送消息,询问我是否确定要删除所有消息,但之后,当我输入“pip yes”(pip 是我的前缀)时它什么也不做,我该如何解决这个问题?

感谢您的帮助!

解决方法

您应该进一步查看client.wait_for。它在不和谐的构建功能中。纯粹!

import asyncio

@client.command()
async def clear(ctx,amount):
   if amount == "all":
      await ctx.send("Are you sure you want to delete all messages in this channel?")

      def check(message):
         if message.author == ctx.author:
            return ctx.author == message.author # Or just return True

      try:
         answer = await client.wait_for('message',timeout = 20.0,check = check)
         if answer.content == "yes":
            await ctx.channel.purge(limit=100000000)
         else:
            # Do something

      except asyncio.TimeoutError:
         await ctx.send('Timeout')

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...