【问题标题】:discord.py "wait_for" a reaction in a commanddiscord.py "wait_for" 命令中的一个反应
【发布时间】:2020-08-25 11:58:51
【问题描述】:

我已经写了一个命令。当您执行此命令时,机器人会向特定频道发送消息。他对此消息添加了一个反应(顺便说一句嵌入)。到目前为止。但是现在,当有人点击这个反应时,我希望机器人做出反应。在这种情况下,他应该向特定频道发送消息。但这不起作用。也没有错误码,应该是可以的,只是他没有发消息。

@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')

没有错误消息。

【问题讨论】:

  • 输出中有错误信息吗?
  • 不,没有错误信息。

标签: python discord.py


【解决方案1】:

看起来您的 reaction.message == mess1 条件似乎正在返回 False,我无法确定发生这种情况的原因,但如果我这样做了,我会对其进行编辑。

解决这个问题的一种方法是评估消息的 ID:

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

当机器人做出反应时,这将评估为True,因此我建议添加另一个条件来检查用户是否做出反应,如果这是您希望用户执行的操作:

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

参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    相关资源
    最近更新 更多