久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何讓不和諧機器人閱讀嵌入

How to get discord bot to read embed(如何讓不和諧機器人閱讀嵌入)
本文介紹了如何讓不和諧機器人閱讀嵌入的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我了解不和諧機器人如何讀取常規用戶輸入的消息并使用

I understand how a discord bot can read a regular user inputed message and respond using

if(message.content.toLowerCase().includes('cyber'))
    message.channel.send("Key Word Detected ");

但如果它是嵌入的,它不會讀取消息.請幫我更改它以在嵌入消息中查找關鍵字并引起機器人的響應.

But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.

推薦答案

MessageEmbed 可以在 author, description, footer, message.contenttitle.它們也可以在每個文件中,因此可能需要檢查所有這些內容.
這是你可以使用的一個小函數(我知道這看起來很亂,但這只是因為有很多邏輯運算符):

The text in a MessageEmbed can be in author, description, footer, message.content and title. They can also be inside every filed, so might want to check for all that stuff.
Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):

/*
      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缺少非可選參數.
你可以這樣使用它:

The functions returns true when finds the word you put in, false when it doesn't find it and null when one of the non-optional arguments is missing.
You can use it like this:

if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");

頂部有一些說明,希望對您有所幫助;)

There are some instructions at the top, hope this helps ;)

這篇關于如何讓不和諧機器人閱讀嵌入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 亚洲专区在线 | 国产精品日韩欧美一区二区三区 | 中文字幕av中文字幕 | 日韩中文字幕在线观看 | 国产精品国产精品国产专区不蜜 | 日韩精品一区二区三区中文字幕 | 91精品久久久久久久久中文字幕 | 日韩欧美国产精品 | 亚洲成人激情在线观看 | 日本一二三区在线观看 | 在线第一页 | 日韩欧美一区在线 | 国产精品久久久久久久久久免费 | 亚洲美女在线视频 | 国产免费一区二区三区 | 精品精品视频 | 日韩性在线 | 观看av | 亚洲精品视频一区二区三区 | 中文字幕一区二区三区在线观看 | 国产精品夜间视频香蕉 | 99精品视频一区二区三区 | 午夜影院 | 亚洲视频免费在线播放 | 最新av中文字幕 | 久久精品成人一区 | 91精品国产欧美一区二区成人 | 国产免费国产 | 丁香婷婷久久久综合精品国产 | 国产精品久久久久无码av | 国产精品久久久久久中文字 | av一区二区三区四区 | 美女131mm久久爽爽免费 | 97在线观视频免费观看 | 国产精品成人国产乱一区 | 亚洲欧美国产精品久久 | 黄色一级大片视频 | 中文字幕av在线播放 | 国产在线精品一区二区三区 | 免费一区二区 | 99国产精品久久久 |