如何在嵌入中显示用户标签和头像?

时间:2021-03-09 08:55:35

标签: python discord discord.py

我编写了一个用于提供建议和帮助的机器人。 我想在嵌入的 footer 中添加作者标签和头像。但是我没有找到任何可以帮助我解决问题的好资源。

这是我的方法

import discord
from discord.ext import commands
import datetime
bot = commands.Bot(command_prefix='*')

suggest_channel = None

class hollow(commands.Cog):


    def init(self, bot):
        self.bot = bot

@commands.Cog.listener("on_message")
async def deletion(self,message):
  if message.channel.id == (799202156771147796):
    if message.author.id == (811243366795837***):
      return
    else:
      await message.delete()
      embed = discord.Embed(
      title=f'Sugestie',
      description=(message.content),
      color = discord.Color.blue()
      )
      embed.set_footer(
      text=f'id:{message.author.id}')
      embed.timestamp= datetime.datetime.utcnow()
      x = await message.channel.send(embed = embed)
      await x.add_reaction(':white_check_mark:')
      await x.add_reaction(':x:')
  elif message.channel.id == (799202157404356638):
    if message.author.id == (811243366795837***):
      return
    else:
      await message.delete()
      embed = discord.Embed(
      title=f'Help requested by:{message.author}',
      description=(message.content),
      color = discord.Color.blue()
      )
      embed.set_footer(
      text=f'id:{message.author.id}')
      embed.timestamp= datetime.datetime.utcnow()
      await message.channel.send(embed = embed)
def setup(bot):
    bot.add_cog(hollow(bot))

另外,对于不和谐的反应,我该如何将此表情符号放入代码中?

1 个答案:

答案 0 :(得分:1)

您可以简单地将 ctx.author.avatar_url 传递给 icon_url 中的 Embed.set_footer kwarg

embed.set_footer(..., icon_url=ctx.author.avatar_url)

回答您的第二个问题,“将此表情符号放入代码中”是什么意思?只需复制粘贴

await ctx.send(":white_check_mark:")

如果你想用它添加一个反应,只需获取带有 \:emoji: 的 unicode 不和谐,发送它并复制消息

await message.add_reaction("✅")