【问题标题】:I want the bot to send an embed after the reaction it sent has been reacted to [duplicate]我希望机器人在它发送的反应对[重复]做出反应后发送嵌入
【发布时间】:2021-06-04 05:32:45
【问题描述】:

到目前为止,我已经让机器人回答了命令,但现在我希望机器人在有人做出反应后回复,这是我尝试过的代码:

@client.command()
async def war(ctx): 
    embed = discord.Embed(title='War', description='You are starting a war, do you want to continue?', color=0x00000)
    msg = await ctx.send(embed=embed)
    await msg.add_reaction(emojigood)
    await msg.add_reaction(emojibad)
    
async def on_reaction_add(reaction, user):
  if reaction.emoji == emojigood:
   embed = discord.Embed(title='War', description='Please now choose a country', color=0x00000)
   await channel.send(embed=embed)

【问题讨论】:

  • 不,我的问题不在于变量。
  • 我参考您的if 声明。这似乎很奇怪。 emojigood 是什么?
  • 我已经制作了 2 个变量 emojigood 和 emojibad,它们会显示 emoji 的竖起大拇指和大拇指向下
  • 他们的价值观是什么? in 运算符的结果是一个布尔值:TrueFalse。因此,将其与emojigood 进行比较似乎没有意义。你的意思是if reaction.emoji == emojigood and 'you sure' in message.content:
  • 那些是我试图测试的东西如果真的应该问,如果反应.emoji==emojigood

标签: python discord.py


【解决方案1】:

这是一段示例代码,用于使用您的示例解释 bot.wait_for() 方法,官方文档也有示例以及有效的方法和属性Here

@client.command()
async def war(ctx): 
    embed = discord.Embed(title='War', description='You are starting a war, do you want to continue?', color=0x00000)
    msg = await ctx.send(embed=embed)
    await msg.add_reaction(emojigood)
    await msg.add_reaction(emojibad)
    def check(r):
        return (r.emoji == emojigood or r.emoji == emojibad) and r.message == msg
    #Checks whether the message is the same, and the emoji is one of the accepted ones, and returns either True or False
    r = await ctx.bot.wait_for('reaction_add', check=check)
    #this is equivalent to a event listener within your command, it will stop there until a reaction that meets the requirements has been found 
    #(This won't block other commands and functions)
    if r.emoji == emojigood:
        embed1 = discord.Embed(title='War', description='Please now choose a country', color=0x00000)
        await ctx.send(embed=embed1)

【讨论】:

  • 我用打印语句试了一下,但是当我反应时它没有在终端打印任何东西
  • 啊,我刚去查了一下,如果你将wait_for语句中的“reaction”更改为“reaction_add”,我认为它应该可以工作
  • @Therandomcoder 也必须是单引号,我永远不记得哪些事情做或不做
  • 输入命令时出现此错误
  • 回溯(最近一次调用最后):文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/commands/bot.py ”,第 939 行,在调用 await ctx.command.invoke(ctx) 文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/commands/core.py ”,第 863 行,在调用等待注入(*ctx.args,**ctx.kwargs)文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/ commands/core.py",第 94 行,已包装
猜你喜欢
  • 2021-04-11
  • 2021-07-04
  • 1970-01-01
  • 2020-12-13
  • 2022-01-08
  • 2020-08-02
  • 2019-09-11
  • 2020-06-13
  • 1970-01-01
相关资源
最近更新 更多