Class Emoji
- Namespace
- Discord
- Assembly
- Discord.Net.Core.dll
A Unicode emoji.
public class Emoji : IEmote
- Inheritance
-
Emoji
- Implements
- Inherited Members
Examples
The sample below sends a message and adds an Emoji and a custom Emote to the message.
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);
}
Result
Remarks
Note
A valid Emoji format is Unicode-based. This means only
something like 🙃
or \U0001f643
would work, instead of
:upside_down:
.
A Unicode-based emoji can be obtained by escaping with a \
in
front of the emote using the Discord chat client or by looking up on
Emojipedia.
This class represents a standard Unicode-based emoji. This type of emoji can be created by passing the Unicode into the constructor.
Constructors
Emoji(string)
Initializes a new Emoji class with the provided Unicode.
public Emoji(string unicode)
Parameters
unicode
stringThe pure UTF-8 encoding of an emoji.
Properties
Name
Gets the display name or Unicode representation of this emote.
public string Name { get; }
Property Value
- string
A string representing the display name or the Unicode representation (e.g.
🤔
) of this emote.
Methods
Equals(object)
Determines whether the specified emoji is equal to the current one.
public override bool Equals(object other)
Parameters
other
objectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Parse(string)
Parse an Emoji from its raw format.
public static Emoji Parse(string emojiStr)
Parameters
emojiStr
stringThe raw encoding of an emoji. For example:
:heart: or ❤
Returns
Exceptions
- FormatException
String is not emoji or unicode!
ToString()
Gets the Unicode representation of this emoji.
public override string ToString()
Returns
TryParse(string, out Emoji)
Tries to parse an Emoji from its raw format.
public static bool TryParse(string text, out Emoji result)
Parameters
Returns
Operators
implicit operator Emoji(string)
public static implicit operator Emoji(string s)
Parameters
s
string