How to get discord bot to read embed











up vote
0
down vote

favorite












I understand how a discord bot can read a regular user inputed message and respond using



if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");


But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.










share|improve this question






















  • It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
    – TankorSmash
    Nov 8 at 5:30










  • I tried changing the code to look like if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); nothing seems to be working and everything I've looked up seems to not have any solution to my problem
    – Mark Farag
    Nov 8 at 5:44












  • Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
    – Djazouli
    Nov 8 at 6:25

















up vote
0
down vote

favorite












I understand how a discord bot can read a regular user inputed message and respond using



if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");


But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.










share|improve this question






















  • It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
    – TankorSmash
    Nov 8 at 5:30










  • I tried changing the code to look like if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); nothing seems to be working and everything I've looked up seems to not have any solution to my problem
    – Mark Farag
    Nov 8 at 5:44












  • Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
    – Djazouli
    Nov 8 at 6:25















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I understand how a discord bot can read a regular user inputed message and respond using



if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");


But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.










share|improve this question













I understand how a discord bot can read a regular user inputed message and respond using



if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");


But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.







javascript discord discord.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 4:11









Mark Farag

1




1












  • It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
    – TankorSmash
    Nov 8 at 5:30










  • I tried changing the code to look like if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); nothing seems to be working and everything I've looked up seems to not have any solution to my problem
    – Mark Farag
    Nov 8 at 5:44












  • Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
    – Djazouli
    Nov 8 at 6:25




















  • It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
    – TankorSmash
    Nov 8 at 5:30










  • I tried changing the code to look like if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); nothing seems to be working and everything I've looked up seems to not have any solution to my problem
    – Mark Farag
    Nov 8 at 5:44












  • Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
    – Djazouli
    Nov 8 at 6:25


















It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
– TankorSmash
Nov 8 at 5:30




It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
– TankorSmash
Nov 8 at 5:30












I tried changing the code to look like if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); nothing seems to be working and everything I've looked up seems to not have any solution to my problem
– Mark Farag
Nov 8 at 5:44






I tried changing the code to look like if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected "); nothing seems to be working and everything I've looked up seems to not have any solution to my problem
– Mark Farag
Nov 8 at 5:44














Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
– Djazouli
Nov 8 at 6:25






Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
– Djazouli
Nov 8 at 6:25














2 Answers
2






active

oldest

votes

















up vote
0
down vote













This should be it, checking for all embeds in the message too



if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
else {
for(var i = 0; i < message.embeds.length; i++) {
if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
message.channel.send("Detected");
break;
}
}





share|improve this answer






























    up vote
    0
    down vote













    The text in a MessageEmbed can be in author, description, footer, message.content and title. They can also be inside every filed, so might want to check for all that stuff.

    Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):





    /*
    message {Discord.Message}: the message you want to search in
    target {string}: the string you're looking for
    {
    caseSensitive {boolean}: whether you want the search to be case case-sensitive
    author {boolean}: whether you want to search in the author's name
    description {boolean}: whether you want to search in the description
    footer {boolean}: whether you want to search in the footer
    title {boolean}: whether you want to search in the title
    fields {boolean}: whether you want to search in the fields
    }
    */
    function findInMessage(message, target, {
    caseSensitive = false,
    author = false,
    description = true,
    footer = true,
    title = true,
    fields = true
    }) {
    if (!target || !message) return null;
    let str = caseSensitive ? target : target.toLowerCase();

    if ((caseSensitive && message.content.includes(str)) ||
    (!caseSensitive && message.content.toLowerCase().includes(str))) return true;

    for (let embed of message.embeds) {
    if ((caseSensitive && (
    (author && embed.author.includes(str)) ||
    (description && embed.description.includes(str)) ||
    (footer && embed.footer.includes(str)) ||
    (title && embed.title.includes(str)))) ||
    (!caseSensitive && (
    (author && embed.author.toLowerCase().includes(str)) ||
    (description && embed.description.toLowerCase().includes(str)) ||
    (footer && embed.footer.toLowerCase().includes(str)) ||
    (title && embed.title.toLowerCase().includes(str))))
    ) return true;

    if (fields)
    for (let field of embed.fields) {
    if ((caseSensitive && [field.name, field.value].includes(str)) ||
    (!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
    }
    }

    return false;
    }


    The functions returns true when finds the word you put in, false when it doesn't find it and null when one of the non-optional arguments is missing.

    You can use it like this:



    if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");


    There are some instructions at the top, hope this helps ;)






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201455%2fhow-to-get-discord-bot-to-read-embed%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      This should be it, checking for all embeds in the message too



      if(message.content.toLowerCase().includes('cyber'))
      message.channel.send("Key Word Detected ");
      else {
      for(var i = 0; i < message.embeds.length; i++) {
      if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
      message.channel.send("Detected");
      break;
      }
      }





      share|improve this answer



























        up vote
        0
        down vote













        This should be it, checking for all embeds in the message too



        if(message.content.toLowerCase().includes('cyber'))
        message.channel.send("Key Word Detected ");
        else {
        for(var i = 0; i < message.embeds.length; i++) {
        if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
        message.channel.send("Detected");
        break;
        }
        }





        share|improve this answer

























          up vote
          0
          down vote










          up vote
          0
          down vote









          This should be it, checking for all embeds in the message too



          if(message.content.toLowerCase().includes('cyber'))
          message.channel.send("Key Word Detected ");
          else {
          for(var i = 0; i < message.embeds.length; i++) {
          if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
          message.channel.send("Detected");
          break;
          }
          }





          share|improve this answer














          This should be it, checking for all embeds in the message too



          if(message.content.toLowerCase().includes('cyber'))
          message.channel.send("Key Word Detected ");
          else {
          for(var i = 0; i < message.embeds.length; i++) {
          if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
          message.channel.send("Detected");
          break;
          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 8 at 11:36

























          answered Nov 8 at 11:00









          Tom Martin

          816




          816
























              up vote
              0
              down vote













              The text in a MessageEmbed can be in author, description, footer, message.content and title. They can also be inside every filed, so might want to check for all that stuff.

              Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):





              /*
              message {Discord.Message}: the message you want to search in
              target {string}: the string you're looking for
              {
              caseSensitive {boolean}: whether you want the search to be case case-sensitive
              author {boolean}: whether you want to search in the author's name
              description {boolean}: whether you want to search in the description
              footer {boolean}: whether you want to search in the footer
              title {boolean}: whether you want to search in the title
              fields {boolean}: whether you want to search in the fields
              }
              */
              function findInMessage(message, target, {
              caseSensitive = false,
              author = false,
              description = true,
              footer = true,
              title = true,
              fields = true
              }) {
              if (!target || !message) return null;
              let str = caseSensitive ? target : target.toLowerCase();

              if ((caseSensitive && message.content.includes(str)) ||
              (!caseSensitive && message.content.toLowerCase().includes(str))) return true;

              for (let embed of message.embeds) {
              if ((caseSensitive && (
              (author && embed.author.includes(str)) ||
              (description && embed.description.includes(str)) ||
              (footer && embed.footer.includes(str)) ||
              (title && embed.title.includes(str)))) ||
              (!caseSensitive && (
              (author && embed.author.toLowerCase().includes(str)) ||
              (description && embed.description.toLowerCase().includes(str)) ||
              (footer && embed.footer.toLowerCase().includes(str)) ||
              (title && embed.title.toLowerCase().includes(str))))
              ) return true;

              if (fields)
              for (let field of embed.fields) {
              if ((caseSensitive && [field.name, field.value].includes(str)) ||
              (!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
              }
              }

              return false;
              }


              The functions returns true when finds the word you put in, false when it doesn't find it and null when one of the non-optional arguments is missing.

              You can use it like this:



              if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");


              There are some instructions at the top, hope this helps ;)






              share|improve this answer

























                up vote
                0
                down vote













                The text in a MessageEmbed can be in author, description, footer, message.content and title. They can also be inside every filed, so might want to check for all that stuff.

                Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):





                /*
                message {Discord.Message}: the message you want to search in
                target {string}: the string you're looking for
                {
                caseSensitive {boolean}: whether you want the search to be case case-sensitive
                author {boolean}: whether you want to search in the author's name
                description {boolean}: whether you want to search in the description
                footer {boolean}: whether you want to search in the footer
                title {boolean}: whether you want to search in the title
                fields {boolean}: whether you want to search in the fields
                }
                */
                function findInMessage(message, target, {
                caseSensitive = false,
                author = false,
                description = true,
                footer = true,
                title = true,
                fields = true
                }) {
                if (!target || !message) return null;
                let str = caseSensitive ? target : target.toLowerCase();

                if ((caseSensitive && message.content.includes(str)) ||
                (!caseSensitive && message.content.toLowerCase().includes(str))) return true;

                for (let embed of message.embeds) {
                if ((caseSensitive && (
                (author && embed.author.includes(str)) ||
                (description && embed.description.includes(str)) ||
                (footer && embed.footer.includes(str)) ||
                (title && embed.title.includes(str)))) ||
                (!caseSensitive && (
                (author && embed.author.toLowerCase().includes(str)) ||
                (description && embed.description.toLowerCase().includes(str)) ||
                (footer && embed.footer.toLowerCase().includes(str)) ||
                (title && embed.title.toLowerCase().includes(str))))
                ) return true;

                if (fields)
                for (let field of embed.fields) {
                if ((caseSensitive && [field.name, field.value].includes(str)) ||
                (!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
                }
                }

                return false;
                }


                The functions returns true when finds the word you put in, false when it doesn't find it and null when one of the non-optional arguments is missing.

                You can use it like this:



                if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");


                There are some instructions at the top, hope this helps ;)






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  The text in a MessageEmbed can be in author, description, footer, message.content and title. They can also be inside every filed, so might want to check for all that stuff.

                  Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):





                  /*
                  message {Discord.Message}: the message you want to search in
                  target {string}: the string you're looking for
                  {
                  caseSensitive {boolean}: whether you want the search to be case case-sensitive
                  author {boolean}: whether you want to search in the author's name
                  description {boolean}: whether you want to search in the description
                  footer {boolean}: whether you want to search in the footer
                  title {boolean}: whether you want to search in the title
                  fields {boolean}: whether you want to search in the fields
                  }
                  */
                  function findInMessage(message, target, {
                  caseSensitive = false,
                  author = false,
                  description = true,
                  footer = true,
                  title = true,
                  fields = true
                  }) {
                  if (!target || !message) return null;
                  let str = caseSensitive ? target : target.toLowerCase();

                  if ((caseSensitive && message.content.includes(str)) ||
                  (!caseSensitive && message.content.toLowerCase().includes(str))) return true;

                  for (let embed of message.embeds) {
                  if ((caseSensitive && (
                  (author && embed.author.includes(str)) ||
                  (description && embed.description.includes(str)) ||
                  (footer && embed.footer.includes(str)) ||
                  (title && embed.title.includes(str)))) ||
                  (!caseSensitive && (
                  (author && embed.author.toLowerCase().includes(str)) ||
                  (description && embed.description.toLowerCase().includes(str)) ||
                  (footer && embed.footer.toLowerCase().includes(str)) ||
                  (title && embed.title.toLowerCase().includes(str))))
                  ) return true;

                  if (fields)
                  for (let field of embed.fields) {
                  if ((caseSensitive && [field.name, field.value].includes(str)) ||
                  (!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
                  }
                  }

                  return false;
                  }


                  The functions returns true when finds the word you put in, false when it doesn't find it and null when one of the non-optional arguments is missing.

                  You can use it like this:



                  if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");


                  There are some instructions at the top, hope this helps ;)






                  share|improve this answer












                  The text in a MessageEmbed can be in author, description, footer, message.content and title. They can also be inside every filed, so might want to check for all that stuff.

                  Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):





                  /*
                  message {Discord.Message}: the message you want to search in
                  target {string}: the string you're looking for
                  {
                  caseSensitive {boolean}: whether you want the search to be case case-sensitive
                  author {boolean}: whether you want to search in the author's name
                  description {boolean}: whether you want to search in the description
                  footer {boolean}: whether you want to search in the footer
                  title {boolean}: whether you want to search in the title
                  fields {boolean}: whether you want to search in the fields
                  }
                  */
                  function findInMessage(message, target, {
                  caseSensitive = false,
                  author = false,
                  description = true,
                  footer = true,
                  title = true,
                  fields = true
                  }) {
                  if (!target || !message) return null;
                  let str = caseSensitive ? target : target.toLowerCase();

                  if ((caseSensitive && message.content.includes(str)) ||
                  (!caseSensitive && message.content.toLowerCase().includes(str))) return true;

                  for (let embed of message.embeds) {
                  if ((caseSensitive && (
                  (author && embed.author.includes(str)) ||
                  (description && embed.description.includes(str)) ||
                  (footer && embed.footer.includes(str)) ||
                  (title && embed.title.includes(str)))) ||
                  (!caseSensitive && (
                  (author && embed.author.toLowerCase().includes(str)) ||
                  (description && embed.description.toLowerCase().includes(str)) ||
                  (footer && embed.footer.toLowerCase().includes(str)) ||
                  (title && embed.title.toLowerCase().includes(str))))
                  ) return true;

                  if (fields)
                  for (let field of embed.fields) {
                  if ((caseSensitive && [field.name, field.value].includes(str)) ||
                  (!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
                  }
                  }

                  return false;
                  }


                  The functions returns true when finds the word you put in, false when it doesn't find it and null when one of the non-optional arguments is missing.

                  You can use it like this:



                  if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");


                  There are some instructions at the top, hope this helps ;)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 8 at 16:52









                  Federico Grandi

                  2,4081926




                  2,4081926






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201455%2fhow-to-get-discord-bot-to-read-embed%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Post-Redirect-Get with Spring WebFlux and Thymeleaf

                      Xamarin.form Move up view when keyboard appear

                      JBPM : POST request for execute process go wrong