Search code examples
c#discordembeddiscord.net

Discord Bot Using Reactions on Embed Message Discord .Net


I'm having some trouble with my Discord bot not being about to add reactions to the embed message Its Sending Any Ideas below is the code I have so far

   [Command("raid")]
        public async Task DisplayPic(string raid, string date)
        {        
            DateTime dateTime = DateTime.Parse(date);
            string day = dateTime.ToString("ddd");

             if (raid == "GoS" && day == "Fri")
            {
               // Emote emote = ":thumbsup:";
                var filename = "Garden_of_Salvation_Friday.png";

                var embed = new EmbedBuilder()
                {
                    Title = "Garden of Salvation",
                    Description = "Must be Level 1230",
                    ImageUrl = $"attachment://{filename}"
                                
                }.Build();

                var myReaction = new Emoji("👍");

                await Context.Channel.SendFileAsync(filename, embed: embed);
                await Context.Message.AddReactionAsync(myReaction);
               
               
            }
        }        

Solution

  • To perform actions on a message which is sent by the bot, you need to assign the message to a variable like so.

    IUserMessage sentMessage = await Context.Channel.SendMessageAsync(...);
    

    In your case you want to add a reaction, so you can use the AddReactionAsync method in the same way that you used it on Context.Message in the code you provided.

    await sentMessage.AddReactionAsync(...);