【问题标题】:(discord.py) Adding reactions to an embed posted by a discord bot(discord.py) 向不和谐机器人发布的嵌入添加反应
【发布时间】:2021-09-04 23:03:57
【问题描述】:

前言:我对 Python 非常缺乏经验,也从未为它上过课。这是我第一次编写 Python 代码/制作 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'))    

【问题讨论】:

    标签: python discord discord.py embed


    【解决方案1】:

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

    来自常见问题的参考:https://discordpy.readthedocs.io/en/stable/faq.html#how-can-i-add-a-reaction-to-a-message

    更新代码:

    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

    【讨论】:

      【解决方案2】:

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

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

      PS:你必须在添加反应时传递一个 unicode emoji,才能在不和谐中获得\:emoji:,发送并复制消息

      【讨论】:

      • 在移动设备上,您可以发送:emoji:(代码块中的表情符号)来获取它,然后看起来像这样:&lt;:emoji:12387592034&gt;
      猜你喜欢
      • 2020-06-29
      • 2018-11-17
      • 2020-11-07
      • 2020-12-25
      • 1970-01-01
      • 2020-12-02
      • 2021-09-09
      • 2023-03-30
      • 2021-03-10
      相关资源
      最近更新 更多