【问题标题】:Read information from embed message Discord.JS从嵌入消息 Discord.JS 中读取信息
【发布时间】:2021-11-07 10:27:31
【问题描述】:

enter image description here 我希望我的 keytritz 机器人在标题为 naruto / Naruto 时对嵌入做出反应,但在第一个中我得到一个错误(#1)但它不影响功能但在第二个嵌入中(#2)我得到了一个错误keytritz 机器人没有反应也没有评论 ,我留下一个链接,两个机器人的代码在哪里, mudae 机器人不是我的。 https://mega.nz/folder/IIUHEabJ#IIaRNcMgUS2gC-d_lZXQZw https://top.gg/bot/432610292342587392

代码 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;
          }
      }

嵌入 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"
      }
    }
  });
  }

错误 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.

错误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)

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    我评估了一些代码以尝试基本上复制您所做的事情。我想出了这个代码。可能对你有一点帮助,而且我用我的其他测试机器人尝试过,我还发现如果你发送一个链接,例如https://google.com,它将有一个嵌入但不和谐它没有意义它只是从其他机器人或 smth 中读取实际嵌入,无论如何,我到目前为止得到了什么。 Discord.js V13

    client.on('messageCreate', message => {
    
        if(message.embeds.length >= 0) 
        // Check if the Message has embed or not
        {
          let embed = message.embeds
          // console.log(embed) just a console.log
    
          for(let i = 0; i < embed.length; i++)
          // Loop it since in v13 you can send multiple embed in single message
          {
            
            if(embed[i].title === null) return;
            // check each embed if it has title or not, if it doesnt then do nothing
    
            if(embed[i].title.toLowerCase().includes('hi'))
            // check each embed if it includes word 'hi' or not
            {
              message.react('?')
              message.react('?')
            }
          }
        }
    
    })
    
    • P.S.此代码将读取另一条机器人消息
    • P.S.S如果有人有更好的方式解释代码或想要进行更改,请随时编辑它

    【讨论】:

      猜你喜欢
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 2021-08-25
      • 2018-08-26
      • 2021-08-22
      • 1970-01-01
      相关资源
      最近更新 更多