【问题标题】:Discord.net is it possible programmatically add a custom server emoji reaction?Discord.net 是否可以以编程方式添加自定义服务器表情符号反应?
【发布时间】:2020-03-09 17:16:03
【问题描述】:

我想知道是否有办法添加属于我们服务器的自定义、非标准表情符号。

这适用于例如:

var context = new SocketCommandContext(_client, message as SocketUserMessage);
await context.Message.AddReactionAsync(new Emoji("????")).ConfigureAwait(false);

但这不起作用

var context = new SocketCommandContext(_client, message as SocketUserMessage);
await context.Message.AddReactionAsync(new Emoji(":MyCustomEmoji:")).ConfigureAwait(false);

问题

有没有办法添加在我们服务器上使用的自定义表情符号?如果有请解释一下。

【问题讨论】:

    标签: c#-3.0 discord discord.net


    【解决方案1】:

    非标准表情符号由Emote Class 管理。这是link to the additional documentation

    这直接取自上面链接的表情类的文档

    public async Task SendAndReactAsync(ISocketMessageChannel channel)
    {
        var message = await channel.SendMessageAsync("I am a message.");
    
        // Creates a Unicode-based emoji based on the Unicode string.
        // This is effectively the same as new Emoji("?").
        var heartEmoji = new Emoji("\U0001f495");
        // Reacts to the message with the Emoji.
        await message.AddReactionAsync(heartEmoji);
    
        // Parses a custom emote based on the provided Discord emote format.
        // Please note that this does not guarantee the existence of
        // the emote.
        var emote = Emote.Parse("<:thonkang:282745590985523200>");
        // Reacts to the message with the Emote.
        await message.AddReactionAsync(emote);
    }
    

    有效的表情格式是 <:emotename:emoteid>。这可以通过使用 Discord 聊天客户端在表情前面使用 \ 转义来获得。

    【讨论】:

    • 我找到了它,供未来的读者阅读。致电context.Guild.Emotes 获取公会表情列表。
    • 这在链接的文档中都有解释——“To obtain the raw string as shown above for your emote, you would need to escape the emote using the escape character \ in chat somewhere.”表情格式是&lt;:name:id&gt;。注意:您提到的上下文仅存在于命令模块中。但是,是的,您可以通过 SocketGuild 实体获取公会的表情列表
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-22
    • 2020-02-12
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    相关资源
    最近更新 更多