| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
Using Emojis

Need your bot to use an emoji? Then you've come to the right place! Here are three examples of using emojis.

Note
  If your bot isn't in the guild you want to use the custom emoji from, it won't work, giving you dpp::err_unknown_emoji.

First - Sending emojis. You have to use its mention, which depends on the type. If it's a default emoji, you use the corresponding character. So, for example, if you wanted to send a nerd emoji, you would use the nerd unicode character. Now, custom emoji. There are two types: static and animated. Their mentions are <:[name]:[id]> and <a:[name]:[id]>, where [name] means the emoji name and [id] is for its ID. When you send such mention, it automatically gets converted into your emoji. Here's an example of sending emojis:

#include <dpp/dpp.h>
#include <dpp/unicode_emoji.h>
int main() {
dpp::cluster bot("Epic Token");
bot.on_log(dpp::utility::cout_logger());
/* We'll be using two emojis: shocked guy and animated mad face. */
dpp::emoji shocked("vahuyi", 1179366531856093214);
dpp::emoji mad("mad", 1117795317052616704, dpp::e_animated); /* We need this third argument, which is an emoji flag. */
bot.on_slashcommand([shocked, mad](const dpp::slashcommand_t& event) {
if (event.command.get_command_name() == "send-emojis") {
/* Here we send our very informative message: three epic emojis. */
event.reply(dpp::unicode_emoji::nerd + shocked.get_mention() + mad.get_mention());
}
});
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(dpp::slashcommand("send-emojis", "Send the emojis", bot.me.id));
}
});
/* Start the bot! */
bot.start(dpp::st_wait);
return 0;
}
dpp::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition cluster.h:89
dpp::emoji
Represents an emoji for a dpp::guild.
Definition emoji.h:64
dpp::interaction::get_command_name
std::string get_command_name() const
Get the command name for a command interaction.
dpp::slashcommand
Represents an application command, created by your bot either globally, or on a guild.
Definition appcommand.h:1449
dpp::unicode_emoji::nerd
constexpr const char nerd[]
Definition unicode_emoji.h:1640
dpp::utility::cout_logger
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
dpp::run_once
auto run_once()
Run some code within an if() statement only once.
Definition once.h:41
dpp::e_animated
@ e_animated
Animated emoji.
Definition emoji.h:53
dpp::st_wait
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition cluster.h:72
dpp::interaction_create_t::command
interaction command
command interaction
Definition dispatcher.h:789
dpp::ready_t
Session ready.
Definition dispatcher.h:1072
dpp::slashcommand_t
User has issued a slash command.
Definition dispatcher.h:806

Now, our bot will send our epic emojis!

Second - Reacting to messages. Sometimes there's something so interesting in the chat that we want to react to it. While we see the emoji we react with, for bots, it's some plain text. There are different formats for different kinds of emoji when reacting too. For unicode, it's simply its character, like when sending. For custom ones it's either [name]:[id] (if static) or a:[name]:[id] (if animated). Let's show our bot's honest reactions!

#include <dpp/dpp.h>
#include <dpp/unicode_emoji.h>
int main() {
dpp::cluster bot("Epic Token", dpp::i_default_intents | dpp::i_message_content);
/* The second argument is a bitmask of intents - i_message_content is needed to see the messages */
bot.on_log(dpp::utility::cout_logger());
/* We'll be using a shocked guy emoji */
dpp::emoji shocked("vahuyi", 1179366531856093214);
dpp::emoji mad("mad", 1117795317052616704, dpp::e_animated); /* We need this third argument, which is an emoji flag. */
bot.on_message_create([&bot, shocked, mad](const dpp::message_create_t& event) {
if (event.msg.content == "I'm hungry") {
/* But if they're hungry */
bot.message_add_reaction(event.msg.id, event.msg.channel_id, dpp::unicode_emoji::cut_of_meat);
/* Let's send some meat to the message, so they don't starve. They will thank us later. */
} else if (event.msg.content == "WHAT?") {
/* If some unknown content shocked the user */
bot.message_add_reaction(event.msg.id, event.msg.channel_id, shocked.format());
/* React to their message with a shocked guy */
} else if (event.msg.content == "I'm unsubscribing") {
/* They are angry! We should also be! */
bot.message_add_reaction(event.msg.id, event.msg.channel_id, mad.format());
/* React to their message with a mad emoji */
}
});
/* Start the bot! */
bot.start(dpp::st_wait);
return 0;
}
dpp::managed::id
snowflake id
Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID,...
Definition managed.h:39
dpp::unicode_emoji::cut_of_meat
constexpr const char cut_of_meat[]
Definition unicode_emoji.h:952
dpp::i_message_content
@ i_message_content
Intent for receipt of message content.
Definition intents.h:112
dpp::i_default_intents
@ i_default_intents
Default D++ intents (all non-privileged intents).
Definition intents.h:142
dpp::message_create_t
Create message.
Definition dispatcher.h:1746
dpp::message_create_t::msg
message msg
message that was created (sent).
Definition dispatcher.h:1753
dpp::message::content
std::string content
Contents of the message.
Definition message.h:2408
dpp::message::channel_id
snowflake channel_id
ID of the channel the message was sent in.
Definition message.h:2386

Yay, our bot has emotions now!

Finally, select menus. These guys are covered here. They require emoji components (name, ID, animated state) to come separately. If the emoji you're using isn't animated, you don't have to specify that. If your emoji is unicode, it doesn't even have an ID, so you only put the character, since both animated state and ID are defaulted to none (false/0).

#include <dpp/dpp.h>
#include <dpp/unicode_emoji.h>
int main() {
dpp::cluster bot("Epic Token");
bot.on_log(dpp::utility::cout_logger());
/* We now have a new character! That's for the select menu. */
dpp::emoji walter("walter_black", 1179374919088361544);
dpp::emoji mad("mad", 1117795317052616704, dpp::e_animated); /* We need this third argument, which is an emoji flag. */
/* The event is fired when someone issues your commands */
bot.on_slashcommand([walter, mad](const dpp::slashcommand_t& event) {
if (event.command.get_command_name() == "select") {
dpp::message msg(event.command.channel_id, "Now.");
msg.add_component(
dpp::component().add_component(
dpp::component()
.set_type(dpp::cot_selectmenu)
.set_placeholder("Say my name.")
.add_select_option(dpp::select_option("Do what?", "Yeah, you do.", "I don't have a damn clue what you're talking about.").set_emoji(dpp::unicode_emoji::thinking))
.add_select_option(dpp::select_option("Heisenberg", "You're goddamn right!", "The one and only").set_emoji(walter.name, walter.id))
.add_select_option(dpp::select_option("I'm unsubscribing", "Wait what", "Pure cruelty").set_emoji(mad.name, mad.id, mad.is_animated())) /* Since our mad emoji is animated, we should tell that to the function */
.set_id("myselectid")
)
);
event.reply(msg);
}
});
bot.on_select_click([](const dpp::select_click_t& event) {
event.reply(event.values[0]);
});
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(dpp::slashcommand("select", "Send the select menu", bot.me.id));
}
});
/* Start the bot! */
bot.start(dpp::st_wait);
return 0;
}
dpp::component
Represents the component object. A component is a clickable button or drop down list within a discord...
Definition message.h:497
dpp::component::set_id
component & set_id(std::string_view id)
Set the id of the component. For action rows, this field is ignored. Setting the id will auto-set the...
dpp::component::add_select_option
component & add_select_option(const select_option &option)
Add a select option.
dpp::interaction::channel_id
snowflake channel_id
Optional: the channel it was sent from.
Definition appcommand.h:1056
dpp::unicode_emoji::thinking
constexpr const char thinking[]
Definition unicode_emoji.h:1691
dpp::cot_selectmenu
@ cot_selectmenu
Select menu for picking from defined text options.
Definition message.h:53
dpp::message
Represents messages sent and received on Discord.
Definition message.h:2363
dpp::select_click_t
Click on select.
Definition dispatcher.h:953
dpp::select_click_t::values
std::vector< std::string > values
select menu values
Definition dispatcher.h:968
dpp::select_option
An option for a select component.
Definition message.h:287
dpp::select_option::set_emoji
select_option & set_emoji(std::string_view n, dpp::snowflake id=0, bool animated=false)
Set the emoji.

Yay, our context menu is now interesting!

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0