我如何检查提到的用户何时做出反应?

时间:2020-12-18 22:43:37

标签: discord.py-rewrite

所以我试图检查某个用户何时做出反应,但我不确定如何。

@bot.command()
@commands.has_any_role("Franchise Owner", "General Manager", "Head Coach")
async def offer(ctx, member:discord.Member):
  embed = discord.Embed(
  )
  embed.add_field(name="⌛ Incoming Offer", value=f"The <:DallasCowboys:788796627161710592> have offered {member}.")
  offer_sent = await ctx.send(embed=embed)
  await offer_sent.add_reaction("<a:CheckMark:768095274949935146>")
  await offer_sent.add_reaction("<a:XMark:768095331555606528>")
  await member.send("You have been offered to the <:DallasCowboys:788796627161710592>. You have 30 minutes to accept/decline.")
  await asyncio.sleep(30)
  await offer_sent.delete()

2 个答案:

答案 0 :(得分:0)

与这篇文章的主题无关,但是当使用 asyncio.sleep 时,它以秒为单位而不是几分钟,这意味着优惠只会持续 30 秒。

您应该将其更改为 await asyncio.sleep(1800)

1800 秒等于 30 分钟

答案 1 :(得分:0)

为此,您可以在 @client.event 命令的外部添加一个 offer 装饰器。就像:

@bot.command()
@commands.has_any_role("Franchise Owner", "General Manager", "Head Coach")
async def offer(ctx, member:discord.Member):
    embed = discord.Embed()
    embed.add_field(name="⌛ Incoming Offer", value=f"The 
        <:DallasCowboys:788796627161710592> have offered {member}.")
    offer_sent = await ctx.send(embed=embed)
    await offer_sent.add_reaction("<a:CheckMark:768095274949935146>")
    await offer_sent.add_reaction("<a:XMark:768095331555606528>")
    await member.send("You have been offered to the <:DallasCowboys:788796627161710592>. 
        You have 30 minutes to accept/decline.")
    await asyncio.sleep(1800) # Replace "30" with 1800, because 1800 in seconds is 30 min.
    await offer_sent.delete()
 
# Reaction detector:

@client.event
async def on_reaction_add(reaction, user):
    reaction1 = "<a:CheckMark:768095274949935146>"
    reaction2 = "<a:XMark:768095331555606528>"
    if reaction.emoji in [reaction1, reaction2]:
        # Do anything after the user reacted
        await reaction.message.channel.id.send(f'{user} reacted with {reaction}!')