【发布时间】:2021-02-21 18:54:31
【问题描述】:
所以我真的是写任何东西的新手,但我一直在尝试操作一个机器人,当另一个机器人产生突袭时,它会ping某个角色。我能够在消息嵌入中检测标题的过程工作,搜索“Raid”的通用关键字,这很棒。但是,当我尝试检测位于字段值中的口袋妖怪名称(顺便说一句,另一个机器人是 Pokeverse)时,我似乎无法检测到该关键字并发送消息以 ping 一个特定的角色。
这就是我在进行突袭并且在嵌入消息的标题中检测到突袭时用于 ping 的内容。但是我不能让它为指定的名称工作,就像下面示例中的“Regice”一样。我尝试寻找有关使用什么而不是 embed.title.includes 的信息,并尝试使用类似 embed.fields[0].includes 的方法,但没有成功。
如果有人可以帮助或指出正确的方向,我将不胜感激。如果我需要在我的帖子中添加更多信息,也请告诉我。我还附上了来自其他机器人的嵌入消息的截图。 也很抱歉代码混乱。
require("dotenv").config()
const Discord = require("discord.js")
const client = new Discord.Client()
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on("message", (msg) => {
if (msg.content === "ping") {
msg.reply("Pong!")
}
})
client.on('message', (message) => {
if (message.author.id === '432616859263827988') {
if (message.embeds.length == 1) {
const embed = message.embeds[0]
if (embed.title.includes("Raid")) {
return message.channel.send('<@&775396443833106453> Raid Time!')
}
}
}
})
client.on('message', (message) => {
if (message.author.id === '432616859263827988') {
if (message.embeds.length == 1) {
const embed = message.embeds[0]
if (embed.title.includes("Swampert")) {
return message.channel.send('<@&775395107146039316> Raid Time!')
}
}
}
})
【问题讨论】:
标签: javascript discord embed