【问题标题】:Detect message's name of sent image检测已发送图像的消息名称
【发布时间】:2020-05-31 03:05:07
【问题描述】:

我在我的 discord 服务器上使用了 pokecord bot,并且我在服务器中也有自己的 bot。我想做一个功能,当 pokecord 发送带有 pokemon spawn 的 messageEmbed 时,我的机器人会对它做出反应。我尝试了message.content.startsWith() 方法,但是因为它是messageEmbed,所以它不起作用。有没有其他方法可以做到这一点?我在想,当你点击 pokemon 图片时,它会在一个名为 PokecordSpawn.jpg 的新选项卡中打开,也许可以通过这种方式完成?

【问题讨论】:

    标签: javascript node.js bots discord discord.js


    【解决方案1】:

    您可以像这样检查MessageEmbed中的图像文件名:

    if (message.embeds) {
      if (message.embeds[0].image.url.includes('PokecordSpawn.jpg')) {
        // Do something
      }
    }
    

    如果消息有多个嵌入,您也可以使用message.embeds.forEach()

    【讨论】:

    • 它会抛出这个错误:UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'image' of undefined
    • 仍然是同样的错误,也许有问题,因为嵌入是由我的机器人根据命令发送的,尽管我把它放在if(message.author === client.user || !message.content.startsWith(PREFIX) || !message.guild) return 之前,因为 pokecord 只发送一次 spawn 嵌入一会儿。
    • 所以我已经通过将第一个 if 语句更改为 message.embeds[0] 来修复它,感谢您的帮助!
    • 顺便说一句,Pokecord 机器人昨天已经关闭:D
    猜你喜欢
    • 2016-10-20
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    • 2013-10-08
    • 2014-03-23
    相关资源
    最近更新 更多