簡體   English   中英

discord.py “wait_for” 命令中的反應

[英]discord.py “wait_for” a reaction in a command

我已經寫了一個命令。 當您執行此命令時,機器人會向特定頻道發送消息。 他對此消息添加了一個反應(順便說一句嵌入)。 到目前為止。 但是現在,當有人點擊這個反應時,我希望機器人做出回應。 在這種情況下,他應該向特定頻道發送消息。 但這不起作用。 也沒有錯誤代碼,這應該意味着它可以工作,只是他沒有發送消息。

@bot.command()
async def buy(ctx, choice):
    channel = bot.get_channel(705836078082424914)
    user = ctx.message.author
    vcrole1 = get(user.guild.roles, id=703562188224331777)
    messagechannel = ctx.message.channel.id
    if ctx.message.channel.id == 705146663135871106:
        if choice == '1':
            if any(role.id == 703562188224331777 for role in ctx.message.author.roles):
                await user.remove_roles(vcrole1)
                await ctx.send(
                    "not important message")
                messtag1 = await channel.send('not important') 
                await messtag1.delete(delay=None)

                embed = discord.Embed(color=0xe02522, title='not important title', description=
                'not important description')
                embed.set_footer(text='not important text')
                embed.timestamp = datetime.datetime.utcnow()

                mess1 = await channel.send(embed=embed)
                await mess1.add_reaction('<a:check:674039577882918931>')

                def check(reaction, user):

                    return reaction.message == mess1 and str(reaction.emoji) ==  '<a:check:674039577882918931>'

                await bot.wait_for('reaction_add', check=check)
                channeldone = bot.get_channel(705836078082424914)
                await channeldone.send('test')

沒有錯誤消息。

看起來您的reaction.message == mess1條件正在返回False ,我無法縮小發生這種情況的范圍,但如果我這樣做了,我會對其進行編輯。

克服這個問題的一種方法是評估消息的 ID:

return reaction.message.id == mess1.id and str(reaction.emoji) == '<a:check:674039577882918931>'

當機器人做出反應時,這將評估為True ,因此我建議添加另一個條件來檢查用戶是否做出了反應,如果這是您希望用戶執行的操作:

return .... and user == ctx.author

參考:

暫無
暫無

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

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