如何在discord中添加自定义表情符号.UI按钮组件



我利用按钮为我的机器人通过discord_ui和discord.py,但我想知道是否有可能做自定义表情符号。我试着这样做:

[Button(custom_id = "next", label = "Next", color = "gray", emoji = "<:emoji_name:id:>")] # emoji itself is redacted for the sake of the question but that's the format

但是,它返回一个无效的表情符号,即使它遵循strdiscord.Emoji格式,它需要据我所知。我该怎么做呢?如果这是可能的话。

我知道已经过去几个月了,但我已经找到了解决办法。

要在按钮中使用自定义表情符号,您需要首先获取它并将其分配给一个变量,然后在按钮上使用它。

@client.command()
async def test(ctx):
emoji = await ctx.guild.fetch_emoji(id)
await ctx.send("test", components = [Button(custom_id = "test", label = "Test", color = "gray", emoji = emoji)])

你的表情符号应该弹出。如果有更优雅的解决方案,请告诉我!

有点晚了,但对将来的用户来说。

对于自定义表情符号,您需要使用discord.PartialEmoji(name, id, animated)而不是<:emoji_name:id:>时使用ui.Button。