Discord Bot嵌入自定义表情符号

时间:2019-03-01 03:23:37

标签: embed emoji discord.py

我正在创建一个python discord机器人,它将以嵌入格式输出消息。

我在不和谐的服务器上添加了一些自定义表情符号,并希望在嵌入消息中使用它们。

我希望它看起来像这样https://imgur.com/a/ezUJXoQ,但使用的表情符号将是自定义表情符号,而不是不一致的默认表情符号。

我也希望表情符号位于“说明”字段中。自定义表情符号在标题中效果很好,但在“说明”中不起作用。

 embed = discord.Embed(title="Here is the **title**! <:emoji1:52342365738338334>", color=0x24045b, description="Here is the emoji again! <:emoji1:52342365738338334>"

1 个答案:

答案 0 :(得分:0)

最简单的方法是获取代表您自定义表情符号的Emoji对象,然后使用它来构建您的字符串

from discord.utils improt get

@bot.command(pass_context=True)
async def respond(ctx):
    emoji = get(ctx.message.server.emojis, name="emoji1")
    embed = Embed(title=f"Here is the **title**! {emoji}", color=0x24045b, description=f"Here is the emoji again! {emoji}")
    await bot.say(embed=embed)

这是一个调试命令,可用于获取有关表情符号的信息

from discord import Embed, Emoji
from discord.ext.commands import Bot

bot = Bot('!')

@bot.command(pass_context=True)
async def debug(ctx, emoji: Emoji):
    embed = Embed(description=f"emoji: {emoji}", title=f"emoji: {emoji}")
    embed.add_field(name="id", value=repr(emoji.id))
    embed.add_field(name="name", value=repr(emoji.name))
    await bot.say(embed=embed)

bot.run("token")

!debug :emojiname:不一致地调用它,它应该为您提供有关该表情符号的信息。如果不存在,那么您可能正在尝试使用不存在的表情符号,或者您的机器人无法看到它(通常,表情符号必须来自调用命令的服务器/正在发布响应)到)