python - Discord.Py 向嵌入消息添加反应
问题描述
因此,我尝试在机器人在文本通道中发送的消息中添加三种不同的反应(表情符号)。
用户在他们的 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)
解决方案
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 文档以获取详细信息。
推荐阅读
- android - 保持 Buttonsheet 处于可折叠状态
- r - 在 R 中进行 POST 调用
- android - Firebase Analytics 为 Android 中的单元测试(Mockito)初始化
- dialogflow-es - 哪个更适合用于 Google 助理?操作 SDK 或 JSON 请求响应
- javascript - 趋势预测 Javascript API
- android - 如何在 Android 中加载带有动画的 cardview GridView?
- ios - UICollectionView 内的单元格无法正确呈现
- javascript - 是否可以从本机模块调用 react-360 方法?
- typo3 - Typo3 Powermail:无法导出多个表单 - 如何添加翻译
- node.js - if/else 在一种情况下使用异步代码