Текст в MessageEmbed
может быть в author
, description
, footer
, message.content
и title
. Они также могут быть внутри каждого поля, поэтому, возможно, захотите проверить все это.
Вот небольшая функция, которую вы могли бы использовать (я знаю, что это кажется беспорядком, но это только потому, что есть много логических операторов):
/*
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;
}
Функция возвращает true
, когда находит введенное вами слово, false
, когда оно не находит его, и null
, когда отсутствует один из необязательных аргументов.
Вы можете использовать это так:
if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");
Вверху есть несколько инструкций, надеюсь, это поможет;)