簡體   English   中英

(discord.py) wait_for 函數不檢查作者是否對消息做出反應

[英](discord.py) wait_for function not checking if author reacted to message

我正在為我的派系機器人創建一個“刪除派系”命令,它要求用戶確認他們想要使用反應刪除他們的派系。 我的代碼如下:

embed = discord.Embed(
    title=":warning: Are you sure?",
    colour=discord.Colour.purple(),
    description=f"Are you sure you want to delete **{name_capital}**? "
                f"*Your members will lose their roles and so will you.*"
)
txt = await ctx.send(embed=embed)
await txt.add_reaction("✅")
await txt.add_reaction("❌")


def check(reaction, user):
    return user == ctx.author and str(reaction.emoji) == "✅" or "❌"


try:
    reaction, user = await self.client.wait_for('reaction_add', timeout=8.0, check=check)
except asyncio.TimeoutError:
    embed = discord.Embed(
        title=":x: Deletion cancelled",
        colour=discord.Colour.purple(),
        description="Message timed out"
    )
    await txt.delete()
    await ctx.send(embed=embed)
else:
    if reaction.emoji == "❌":
        await txt.delete()
    elif reaction.emoji == "✅":
        pass  # delete faction code

該命令在大多數情況下都有效。 但是,它也適用於對消息做出反應的其他用戶,盡管我聲明不會在檢查功能中發生。

出了什么問題,我該如何解決?

只是猜測,但您的檢查功能可能格式不正確。 應該是這樣的:

def check(reaction, user):
    return user == ctx.author and (str(reaction.emoji) == "✅" or "❌")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM