是否可以使用 discord.py 从您的计算机将自定义反应图像文件添加到您的消息中?

Is it possible to add a custom reaction image file from your computer to your message using discord.py?

我正在尝试将两个自定义表情符号添加到我的 bot 消息中。要添加自定义表情符号,如果我没记错的话,我可能必须购买 discord nitro/prime 才能在其他服务器中使用它。有什么方法可以不用花钱就可以使用我的自定义表情符号吗?

我在想是否可以从我的计算机文件中读取图像,然后将其转换为自定义反应供我的机器人使用。到目前为止,我没有代码,因为我真的不知道如何在 Python/Discord.py

中使用 Pillow 和图像编辑

您可以使用 create_custom_emoji().

用法:

server = discord.utils.get(client.guilds, id=123456789)  # your server's ID
with open("PATH TO YOUR IMAGE", "rb") as image:
    server.create_custom_emoji(name="EMOJI NAME", image=image)

这是文档中的页面:https://discordpy.readthedocs.io/en/latest/api.html?highlight=create_custom_emoji#discord.Guild.create_custom_emoji

解决方案

我基本上只需要获取表情符号的 ID,然后获取它的名称。您可以通过复制所需反应的 link 来获取 ID。只需右键单击它并复制 link。复制 link 后,将其粘贴到您的浏览器中,您应该会看到您的表情符号弹出到您的浏览器中。

比如这个linkhttps://cdn.discordapp.com/emojis/755076996945543208.png?v=1。我只需要复制数字,即 755076996945543208.

获取到id后,我们需要获取emoji名称。这很容易,我相信每个人都知道怎么做。

获取表情符号名称和id后,您要做的就是这个。

@client.command()
async def poll(ctx, *, message):
    msg = await ctx.send(f"**{message}**")
    await msg.add_reaction(emoji="name_of_emoji:emoji_id")

感谢所有参与并为这个问题做出贡献的人,感谢你们的帮助。 :D