python - Discord.Py 向嵌入的消息添加 react

标签 python discord

因此,我正在尝试向机器人在文本 channel 中发送的消息添加三种不同的 react (表情符号)。

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

  • 固定
  • 不会修复
  • 不是错误

然后,根据管理员按下的表情符号,消息将传输到文本 channel 。

但是!我似乎无法弄清楚您实际上是如何将 react 添加到消息本身的,我已经进行了大量的谷歌搜索,但找不到答案。

代码:

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)

最佳答案

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

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

您可以使用 msg 来添加对该特定消息的 react

await msg.add_reaction("💖")

阅读 discord.py 文档以获取详细信息。

Message.add_reaction

关于python - Discord.Py 向嵌入的消息添加 react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62958944/

相关文章:

Python numpy : column arrays (2d) or lists (1d)

python - Cartopy 和 matplotlib TypeError : unhashable type: 'MultiLineString'

python - 如何使用 Discord.py 向所有文本 channel 发送消息?

javascript - client.startTyping 不是一个函数(Discord.JS)

javascript - Discord JS - DiscordAPIError : Missing Access

Python逐行可视化工具

python - 如果另一个表中存在一行,则添加 bool 字段?

python - 在类中设置可在运行时修改的静态字典的 Pythonic 方法是什么?

java - Jar 文件在 Windows 上完美运行,但在 Rasp Pi 内的 Ubuntu 上运行失败

discord - 启动 Discord 时出现问题 (Fedora 35)