(discord.py) 向不和谐机器人发布的嵌入添加反应

时间:2021-06-21 08:57:30

标签: python discord discord.py embed

前言:我对 Python 非常缺乏经验,而且从未上过这门课。这是我第一次编写 Python 代码/制作 Discord 机器人。

在这里,我有一个由特定消息触发的嵌入。我正在使用一个不和谐的票务机器人(创建对消息做出反应的人专用的新频道)(计划在未来制作我自己的)并且每次创建新票证时,都会发送此嵌入。 我在这里看到过关于通过引用 Discord 服务器上的频道 ID 向嵌入添加反应的帖子,但是我不能这样做。 每次我想要反应时,嵌入都会发送到一个全新的频道添加。我不确定我是不是对 Python 不够了解,无法真正做到这一点,或者它是否真的无法做到。无论如何,在尝试解决此问题时,将不胜感激。需要明确的是:我希望在创建的每个嵌入(不是在一个特定频道中,而是在动态创建的频道中)一起添加反应。

import discord
import os


client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):

    if message.content.startswith('Welcome to Parakeets Mods'):
      embed = discord.Embed(title="Product Select", description="React to the emojis corresponding with what you need", color=0xE91E63)
      embed.add_field(name="​", value="<:dmu:841700430764310559> = ***-*** \n\n <:damascus:841700430492860466> = ***-*** \n\n <a:prestige10:841700430010777651> = ***-*** \n\n  <:ruavt:856345494674472980> = ***-*** \n\n ❓ = ***Questions***")
      await message.channel.send(embed=embed)
    #insert add reaction to above embed

client.run(os.getenv('TOKEN'))    

2 个答案:

答案 0 :(得分:2)

您可以定义要发送的消息并对其添加反应

msg = await message.channel.send(embed=embed)
await msg.add_reaction("✅")

PS:您必须在添加反应时传递 Unicode 表情符号,以使其\:emoji:不和谐,发送和复制消息

答案 1 :(得分:0)

您可以使用 add_reaction("emoji_here") 添加反应。您还需要定义机器人发送的消息以使其工作。

来自常见问题的参考:documentation

更新代码:

import discord
import os


client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):

    if message.content.startswith('Welcome to Parakeets Mods'):
      embed = discord.Embed(title="Product Select", description="React to the emojis corresponding with what you need", color=0xE91E63)
      embed.add_field(name="​", value="<:dmu:841700430764310559> = ***-*** \n\n <:damascus:841700430492860466> = ***-*** \n\n <a:prestige10:841700430010777651> = ***-*** \n\n  <:ruavt:856345494674472980> = ***-*** \n\n ❓ = ***Questions***")
      embed_message = await message.channel.send(embed=embed)
      await embed_message.add_reaction("?")
 

client.run(os.getenv('TOKEN'))    

稍后谢谢我 :D