亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號