为了账号安全,请及时绑定邮箱和手机立即绑定

Discord.Py 向嵌入消息添加反应

Discord.Py 向嵌入消息添加反应

海绵宝宝撒 2023-03-16 11:03:39
因此,我正在尝试向机器人在文本通道中发送的消息添加三种不同的反应(表情符号)。用户在他们的 DM 中填写一个表格,然后消息被发送到一个名为“admin-bug”的文本通道,然后服务器的管理员可以对三种不同的表情符号做出反应:固定的不会被修复不是错误然后,根据管理员按下的表情符号,消息将被传输到文本频道。但!我似乎无法弄清楚您实际上是如何将反应添加到消息本身的,我已经进行了大量的谷歌搜索,但找不到答案。代码:import discordfrom discord.ext import commandsTOKEN = '---'bot = commands.Bot(command_prefix='!!')reactions = [":white_check_mark:", ":stop_sign:", ":no_entry_sign:"]@bot.eventasync 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) herebot.run(TOKEN)
查看完整描述

4 回答

?
白猪掌柜的

TA贡献1893条经验 获得超10个赞

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


查看完整回答
反对 回复 2023-03-16
?
慕森卡

TA贡献1806条经验 获得超8个赞

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


查看完整回答
反对 回复 2023-03-16
?
MMTTMM

TA贡献1869条经验 获得超4个赞

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


message = await adminBug.send(embed=embed)  # save embed as "message"

await message.add_reaction('xxx')           # add reaction to "message"


查看完整回答
反对 回复 2023-03-16
?
绝地无双

TA贡献1946条经验 获得超4个赞

我不确定,因为我使用的是 nextcord(并且有效),但我认为这可行:


@bot.command

async def testembed(ctx):

    embed = discord.Embed(title='Test !', description='This is a test embed !')

    msg = await ctx.send("", embed=embed)

    msg = msg.fetch()   # Notice this line ! It's important !

    await msg.add_reaction('emoji_id')


查看完整回答
反对 回复 2023-03-16
  • 4 回答
  • 0 关注
  • 70 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信