Python I';我正在尝试让用户回复bot响应,然后发送另一条消息

Python I';我正在尝试让用户回复bot响应,然后发送另一条消息,python,discord,discord.py,Python,Discord,Discord.py,如何使机器人再次响应?我试图让机器人让用户对发送的消息做出响应,然后回复说如果太晚了或者是他们做了 import discord from discord.ext import commands import time import random @commands.command(aliases=["RandomChocolate", "choco"]) @commands.cooldown(1, 15, commands.BucketType.user) asyn

如何使机器人再次响应?我试图让机器人让用户对发送的消息做出响应,然后回复说如果太晚了或者是他们做了

  import discord
  from discord.ext import commands
  import time
  import random
  @commands.command(aliases=["RandomChocolate", "choco"])
  @commands.cooldown(1, 15, commands.BucketType.user)
  async def chocolate(self, ctx):
    food=["hershey", "kitkat", "milk"]
    rF = random.choice(food)
    rFC = rF[:1]
    rFL = rF[-1]
    await ctx.send(f"**Hint:** It starts with **{rFC}** 
    and ends with **{rFL}**, you have 15 seconds to answer 
     by the way.")
     if ctx.message.content == rF:
       await ctx.send("Ok")
     else:
       time.sleep(15)
       await ctx.send(f"Too Late!")

您不想将其捆绑到一个命令中。另外,
time.sleep
停止整个程序,
asyncio.sleep
暂停当前运行的协同程序

导入异步IO
进口不和
从discord.ext导入命令
导入时间
随机输入
巧克力用户={}
@commands.command(别名=[“随机巧克力”,“巧克力”])
@冷却时间(1,15,commands.BucketType.user)
异步def巧克力(自身,ctx):
食品=[“好时”、“kitkat”、“牛奶”]
rF=随机选择(食物)
rFC=rF[:1]
rFL=rF[-1]
等待ctx.send(f“**提示:**以**{rFC}**开头,以**{rFL}**结尾,顺便说一下,您有15秒的时间回答。”)
巧克力用户[ctx.message.author.id]=[rF,time.time()+15]
@client.event()
异步def on_消息(消息):
如果cocolate_users.keys()中的message.author.id:#检查用户是否开始猜测,否则什么也不做
数据=用户[message.author.id]
如果time.time()>数据[1]:
wait message.channel.send('抱歉,您超过了15秒的时间限制')
del chocolate_用户[message.author.id]
elif message.content.lower()!=数据[0]:
等待message.channel.send('抱歉,这是错误的,请重试')
其他:
等待message.channel.send('干得好,没错!')
##当你做对的时候会发生其他事情##
del chocolate_用户[message.author.id]

这样做的唯一缺点是,它会等到您发送消息后再告诉您时间已过。

您可以使用
wait bot.wait_for('message')
等待消息。通过传递
check
参数,我们还可以指定等待的消息的详细信息。我正在重新使用我的
消息\u check
来自

class MyCog(commands.Cog):
  def __init__(self, bot):
    self.bot = bot
  @commands.command(aliases=["RandomChocolate", "choco"])
  @commands.cooldown(1, 15, commands.BucketType.user)
  async def chocolate(self, ctx):
    food=["hershey", "kitkat", "milk"]
    rF = random.choice(food)
    rFC = rF[:1]
    rFL = rF[-1]
    await ctx.send(f"**Hint:** It starts with **{rFC}** 
    and ends with **{rFL}**, you have 15 seconds to answer 
     by the way.")
    try:
      response = await self.bot.wait_for("message", timeout=15, check=message_check(channel=ctx.channel, author=ctx.author, content=rF))
      await ctx.send("OK")
    except asyncio.TimeoutError:
      await ctx.send("Too Late!")