【问题标题】:Discord.Py adding reactions to an embeded messageDiscord.Py 向嵌入式消息添加反应
【发布时间】:2020-11-07 13:17:02
【问题描述】:

因此,我尝试将三种不同的反应(表情符号)添加到机器人在文本通道中发送的消息中。

用户在他们的 DM 中填写一个表格,然后消息被发送到一个名为“admin-bug”的文本通道,服务器的管理员然后可以对三个不同的表情符号做出反应:

  • 已修复
  • 不会修复
  • 不是错误

然后,根据管理员按下的表情符号,消息将被转移到文本频道。

但是!我似乎无法弄清楚你实际上是如何将反应添加到消息本身的,我已经做了一堆谷歌搜索,但找不到答案。

代码:

import discord
from discord.ext import commands

TOKEN = '---'
bot = commands.Bot(command_prefix='!!')

reactions = [":white_check_mark:", ":stop_sign:", ":no_entry_sign:"]


@bot.event
async def on_ready():
    print('Bot is ready.')


@bot.command()
async def bug(ctx, desc=None, rep=None):
    user = ctx.author
    await ctx.author.send('```Please explain the bug```')
    responseDesc = await bot.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
    description = responseDesc.content
    await ctx.author.send('````Please provide pictures/videos of this bug```')
    responseRep = await bot.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
    replicate = responseRep.content
    embed = discord.Embed(title='Bug Report', color=0x00ff00)
    embed.add_field(name='Description', value=description, inline=False)
    embed.add_field(name='Replicate', value=replicate, inline=True)
    embed.add_field(name='Reported By', value=user, inline=True)
    adminBug = bot.get_channel(733721953134837861)
    await adminBug.send(embed=embed)
    # Add 3 reaction (different emojis) here

bot.run(TOKEN)

【问题讨论】:

    标签: python discord


    【解决方案1】:

    discord.py 文档有一个关于添加反应的常见问题解答帖子,它有多个示例和深入的描述,此外Messageable.send 返回消息发送,因此您可以在上面使用Message.add_reactionhttps://discordpy.readthedocs.io/en/neo-docs/faq.html#how-can-i-add-a-reaction-to-a-message

    【讨论】:

      【解决方案2】:

      Messagable.send 返回它发送的消息。因此,您可以使用该消息对象向它添加反应。简单地说,您必须使用一个变量来定义机器人发送的消息。

      embed = discord.Embed(title="Bug report")
      embed.add_field(name="Name", value="value")
      msg = await adminBug.send(embed=embed)
      

      您可以使用msg 为该特定消息添加反应

      await msg.add_reaction("?")
      

      阅读 discord.py 文档了解详细信息。

      Message.add_reaction

      【讨论】:

        【解决方案3】:

        您需要将嵌入保存为变量,这样您就可以添加反应。

        message = await adminBug.send(embed=embed)  # save embed as "message"
        await message.add_reaction('xxx')           # add reaction to "message"
        

        【讨论】:

        • 如果您能解释这如何帮助解决问题,将会更有帮助。原来的发帖人现在可能已经解决了他们的问题,所以请编辑你的答案,思考如何最好地为有类似问题的人增加价值,并在未来找到这个答案。
        猜你喜欢
        • 2019-09-06
        • 2020-10-27
        • 2021-07-25
        • 1970-01-01
        • 1970-01-01
        • 2021-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多