【问题标题】:How can I display the user tag and avatar in an embed?如何在嵌入中显示用户标签和头像?
【发布时间】:2021-03-10 16:41:34
【问题描述】:

我已经编写了一个用于提供建议和帮助的机器人。 我想在嵌入的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))

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

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

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

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

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

    await ctx.send(":white_check_mark:")
    

    如果您想对其添加反应,只需获取带有 \:emoji: 不和谐的 unicode,发送并复制消息

    await message.add_reaction("✅")
    

    【讨论】:

      猜你喜欢
      • 2020-12-19
      • 2018-07-07
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      相关资源
      最近更新 更多