using-emojis

# Using Emojis

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

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>

    intmain(){
    dpp::clusterbot("EpicToken");

    bot.on_log(dpp::utility::cout_logger());

    /*We'llbeusingtwoemojis:shockedguyandanimatedmadface.*/
    dpp::emojishocked("vahuyi",1179366531856093214);
    dpp::emojimad("mad",1117795317052616704,dpp::e_animated);/*Weneedthisthirdargument,whichisanemojiflag.*/

    bot.on_slashcommand([shocked,mad](constdpp::slashcommand_t&event){
    if(event.command.get_command_name()=="send-emojis"){
    /*Herewesendourveryinformativemessage:threeepicemojis.*/
    event.reply(dpp::unicode_emoji::nerd+shocked.get_mention()+mad.get_mention());
    }
    });

    bot.on_ready([&bot](constdpp::ready_t&event){
    if(dpp::run_once<struct register_bot_commands>()){
    bot.global_command_create(dpp::slashcommand("send-emojis","Sendtheemojis",bot.me.id));
    }
    });

    /*Startthebot!*/
    bot.start(dpp::st_wait);
    return0;
    }

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>

    intmain(){
    dpp::clusterbot("EpicToken",dpp::i_default_intents|dpp::i_message_content);
    /*Thesecondargumentisabitmaskofintents-i_message_contentisneededtoseethemessages*/

    bot.on_log(dpp::utility::cout_logger());

    /*We'llbeusingashockedguyemoji*/
    dpp::emojishocked("vahuyi",1179366531856093214);
    dpp::emojimad("mad",1117795317052616704,dpp::e_animated);/*Weneedthisthirdargument,whichisanemojiflag.*/

    bot.on_message_create([&bot,shocked,mad](constdpp::message_create_t&event){
    if(event.msg.content=="I'mhungry"){
    /*Butifthey'rehungry*/
    bot.message_add_reaction(event.msg.id,event.msg.channel_id,dpp::unicode_emoji::cut_of_meat);
    /*Let'ssendsomemeattothemessage,sotheydon'tstarve.Theywillthankuslater.*/

    }elseif(event.msg.content=="WHAT?"){
    /*Ifsomeunknowncontentshockedtheuser*/
    bot.message_add_reaction(event.msg.id,event.msg.channel_id,shocked.format());
    /*Reacttotheirmessagewithashockedguy*/

    }elseif(event.msg.content=="I'munsubscribing"){
    /*Theyareangry!Weshouldalsobe!*/
    bot.message_add_reaction(event.msg.id,event.msg.channel_id,mad.format());
    /*Reacttotheirmessagewithamademoji*/
    }
    });

    /*Startthebot!*/
    bot.start(dpp::st_wait);
    return0;
    }

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>

    intmain(){
    dpp::clusterbot("EpicToken");

    bot.on_log(dpp::utility::cout_logger());

    /*Wenowhaveanewcharacter!That'sfortheselectmenu.*/
    dpp::emojiwalter("walter_black",1179374919088361544);
    dpp::emojimad("mad",1117795317052616704,dpp::e_animated);/*Weneedthisthirdargument,whichisanemojiflag.*/

    /*Theeventisfiredwhensomeoneissuesyourcommands*/
    bot.on_slashcommand([walter,mad](constdpp::slashcommand_t&event){
    if(event.command.get_command_name()=="select"){
    dpp::messagemsg(event.command.channel_id,"Now.");
    msg.add_component(
    dpp::component().add_component(
    dpp::component()
    .set_type(dpp::cot_selectmenu)
    .set_placeholder("Saymyname.")
    .add_select_option(dpp::select_option("Dowhat?","Yeah,youdo.","Idon'thaveadamncluewhatyou'retalkingabout.").set_emoji(dpp::unicode_emoji::thinking))
    .add_select_option(dpp::select_option("Heisenberg","You'regoddamnright!","Theoneandonly").set_emoji(walter.name,walter.id))
    .add_select_option(dpp::select_option("I'munsubscribing","Waitwhat","Purecruelty").set_emoji(mad.name,mad.id,mad.is_animated()))/*Sinceourmademojiisanimated,weshouldtellthattothefunction*/
    .set_id("myselectid")
    )
    );
    event.reply(msg);
    }
    });

    bot.on_select_click([](constdpp::select_click_t&event){
    event.reply(event.values[0]);
    });

    bot.on_ready([&bot](constdpp::ready_t&event){
    if(dpp::run_once<struct register_bot_commands>()){
    bot.global_command_create(dpp::slashcommand("select","Sendtheselectmenu",bot.me.id));
    }
    });

    /*Startthebot!*/
    bot.start(dpp::st_wait);
    return0;
    }

Yay, our context menu is now interesting!