如何从消息中删除/自动删除反应?

时间:2021-01-16 22:36:52

标签: python events discord discord.py

我正在创建一个问题机器人。在这里,机器人会提出不同的问题,并给出不同的回应方式。我想保留这种可能性。但我需要一个事件,在用户提交后删除此消息下的反应。不幸的是,我并没有真正找到任何东西,但是我会用 raw_reaction 事件做一些事情,我是对的,这需要怎么看?我还认为我还需要定义所有代码来获取消息的反应,是这样吗? 到目前为止我的代码:

    @commands.command()
    async def trivia_q(self, ctx):
        await ctx.send("Test, check your DMs")

        def check(m):
            return ctx.author == m.author and isinstance(m.channel, discord.DMChannel)

        e = discord.Embed(color=discord.Color.gold())
        e.title = "New question, new luck."
        e.description = "**When was Steve Jobs born?**"
        e.add_field(name="1️⃣", value="02/24/1955", inline=False)
        e.add_field(name="2️⃣", value="03/24/1955", inline=False)
        e.add_field(name="3️⃣", value="02/24/1965", inline=False)
        e.set_footer(text="You have x-x to answer this question.", icon_url=self.bot.user.avatar_url)
        e.timestamp = datetime.datetime.utcnow()
        question = await ctx.send(embed=e)
        await question.add_reaction("1️⃣")
        await question.add_reaction("2️⃣")
        await question.add_reaction("3️⃣")
        try:
            question = await self.bot.wait_for('reaction_add', timeout=60.0, check=check)
        except asyncio.TimeoutError:
            await ctx.author.send("You took to long to react.")
            return
        await asyncio.sleep(10)
        e2 = discord.Embed(color=discord.Color.gold())
        e2.title = "New question, new luck."
        e2.description = "Test1"
        e2.add_field(name="1️⃣", value="02/24/1955")
        e2.add_field(name="2️⃣", value="03/24/1955")
        e2.add_field(name="3️⃣", value="02/24/1965")
        e2.set_footer(text="You have x-x to answer this question.")
        e2.timestamp = datetime.datetime.utcnow()
        await question.edit(embed=e2)
        await question.add_reaction("1️⃣")
        await question.add_reaction("2️⃣")
        await question.add_reaction("3️⃣")

编辑:我想这将是一个仅限 DM 的命令,还不确定 - 也许会更容易。

我现在得到的错误代码是:

TypeError: check() takes 1 positional argument but 2 were given

我将如何继续?

1 个答案:

答案 0 :(得分:1)

您可以一次删除消息中的所有反应:

question = await ctx.send(embed=e)
await question.clear_reactions()

如果您在用户响应后尝试执行此操作,请使用 await bot.wait_for("message", check=some_check_function)

见:https://discordpy.readthedocs.io/en/latest/api.html#discord.Client.wait_for