首页 > 解决方案 > Discord.Py 删除许多特定消息

问题描述

我有一个发送消息(msg)的函数,一旦用户对该消息做出反应,它就会被删除。

该消息应该出现多次,我遇到的问题是一旦用户对其中一条消息做出反应,所有这些消息都会被删除。

我怎样才能使被删除的消息也是用户反应的消息,而不是所有消息?

async def colorpop(ctx):
    chance= random.randint(0,10)
    if chance > 7:
      picker = random.randint(1,3)
      if picker == 1:
        color="red"

      elif picker == 2:
        color="green"

      elif picker == 3:
        color="blue"

      embed = discord.Embed (
      title="New Color",
      description="React to get this color"
      )
      

      msg = await ctx.channel.send(embed=embed)
      
      await msg.add_reaction('')
      def check(reaction, user):
          return str(reaction.emoji) == '' and user != bot.user

      try:
          reaction, user = await bot.wait_for('reaction_add', timeout=timer, check=check)
          await msg.delete()
          await ctx.send("You got the color!")

      except asyncio.TimeoutError:

标签: python-3.xdiscord.py

解决方案


推荐阅读