Discord.NET Adding Reactions to a SocketMessage

JarFile picture JarFile · Oct 14, 2017 · Viewed 12k times · Source

I am using Discord.NET version 1.0.2 to clear things up

I have a MessageReceived Task in my Discord Bot application:

private async Task MessageReceived(SocketMessage message)

This task, as can already be deducted, runs every time a message is received in Discord to this bot. I am trying to figure out how to add a reaction to a message that the bot has received, however. Under SocketMessage there are no methods to add reactions to the message received. I looked online and found that RestUserMessage contains the method AddReactionAsync(IEmote, RequestOptions). I then casted Socket Message to a RestUserMessage as so

var rMessage = (RestUserMessage) await message.Channel.GetMessageAsync(message.Id);

Running the AddReactionAsync method under my variable rMessage for RestUserMessage works, but the parameters are not taken correctly as I can perceive from my reading online and the documentation.

IEmote appears to be a string, but a string does not fulfill this parameter, saying that there is no conversion from a String to an IEmote. I tried casting this String to an IEmote but that did not work.

The RequestOptions variable seems to fulfill the parameter perfectly fine as a new RequestOptions().

My full code for this is:

private async Task MessageReceived(SocketMessage message)
{
    var rMessage = (RestUserMessage) await message.Channel.GetMessageAsync(message.Id);
    rMessage.AddReactionAsync(???, new RequestOptions());
}

How do I fulfill this IEmote parameter correctly and or how do I define an IEmote variable. Also, is defining a new RequestOptions() variable the correct thing to fulfill this parameter as well. Is this also the correct way to add reactions to a message through Discord.NET and if not what is?

The research I have done:

https://github.com/RogueException/Discord.Net/issues/490
https://discord.foxbot.me/docs/api/Discord.Rest.RestUserMessage.html
https://discord.foxbot.me/docs/api/Discord.IEmote.html
https://discord.foxbot.me/docs/api/Discord.RequestOptions.html

Answer

Unknown picture Unknown · Oct 14, 2017

If you head over to Emojipedia, and grab the unicode version as shown below : enter image description here

After that is copied, you have to create a new Emoji object, like so :

var YourEmoji = new Emoji("😀");

You can then add a reaction to the desired message, I'm going to use Context.Message :

Context.Message.AddReactionAsync(YourEmoji);