首页 > 解决方案 > 如何使机器人能够显示来自任何服务器的任何表情符号的链接

问题描述

所以这个命令有效,但......

    @commands.command()
    async def se(self, ctx, emoji: discord.Emoji):
        await ctx.send(f"**Name:**Illdo this later **Link:**{emoji.url}")

它仅适用于机器人所在服务器的表情符号。有谁知道如何使它能够获取任何服务器表情符号的链接?即使机器人不在其中,如果您愿意,我也需要帮助来显示表情符号的名称

我要做的事情是

在此处输入图像描述 谢谢你!

标签: discord.py

解决方案


您需要获取表情符号的 id 并制作 url 本身

你可以id通过一些得到它,split()你还需要检查它是否是动画的,以便我们可以使用.gif.png相应地使用

下面是代码:

@commands.command()
async def se(self, ctx, *, msg):
    _id = msg.split(":") # split by ":"
    if "<a" == _id[0]: # animated emojis structure <a:name:id>
        ext = "gif"
    else:
        ext = "png" # normal emojis structure <name:id>
    e_id = _id[2].split(">")[0].strip()# get the id
    # url for a emoji is like this, try yourself if you want to check by manually copying any emoji's url
    url = f"https://cdn.discordapp.com/emojis/{e_id}.{ext}"
    await ctx.send(f"**Name**: :{_id[1]}: **Link**: {url}")

推荐阅读