Read information from embed message Discord.JS

I want my keytritz bot to react to an embed when the title is naruto / Naruto but in the first one I got an error (# 1) but it did not affect the functionality but in the second embed (#2) I got an error that the keytritz bot did not react and did not commented
, I leave a link where is the code of both bots, the mudae bot is not mine.


CODE Keytritz:

      for(var i = 0; i < message.embeds.length; i++) {
        message.channel.send(message.content.embeds);
          if(message.embeds[i].title.includes("naruto")){
              message.react(" ")
              message.channel.send("Detected");
              break;
          }
      }

Embed lxXxandresxXxl

  if(message.content.startsWith(prefix+"r")) {
    message.channel.send({ embed: {
      color: 3447003,
      author: {
        name: client.user.username,
        icon_url: client.user.displayAvatarURL()
      },
      title: "This is an naruto embed",
      url: "http://google.com",
      description: "This is a test embed to showcase what they look like and what they can do.",
      fields: [{
        name: "Fields",
        value: "They can have different fields with small headlines."
      },
      {
        name: "Masked links",
        value: "You can put [masked links](http://google.com) inside of rich embeds."
      },
      {
        name: "Markdown",
        value: "You can put all the *usual* **__Markdown__** inside of them."
      }
      ],
      timestamp: new Date(),
      footer: {
        icon_url: client.user.displayAvatarURL(),
        text: "© Example"
      }
    }
  });
  }

Error 1#

(node:1744) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
        at RequestHandler.execute (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
        at processTicksAndRejections (internal/process/task_queues.js:88:5)
        at async RequestHandler.push (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
    (node:1744) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
    (node:1744) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Error 2#

if(message.embeds[i].title.includes("naruto")){
                                   ^
TypeError: Cannot read property 'includes' of null
at Client.<anonymous> (/app/server.js:90:36)
    at Client.emit (events.js:196:13)
    at MessageCreateAction.handle (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (events.js:196:13)
    at Receiver.receiverOnMessage (/rbd/pnpm-volume/8bd4e7c9-1711-40fc-be45-7d082848ec2a/node_modules/.registry.npmjs.org/discord.js/12.5.3/node_modules/discord.js/node_modules/ws/lib/websocket.js:983:20)

I’m always a little surprised when people use Glitch support for things like Discord bot issues. Wouldn’t it be wise to check the Discord.Js discord server? In both error messages however the immediate error is displayed. You cannot send an empty message and the title property is null. I’d guess that embeds[i] is null in that case.

Add console.log statements where they can confirm the values you think you have.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.