【问题标题】:How do I check for a word in a message, in discord js?如何在discord js中检查消息中的单词?
【发布时间】:2022-01-10 20:48:35
【问题描述】:

我正在尝试制作一个简单的不和谐机器人。我怎样才能使它检查消息中的单词?例如,如果有人说“我爱香蕉”,而触发词是香蕉,机器人会回应“相同”。我能想出的只是如何让它回复特定的消息(比如只有“香蕉”),我如何制作像我做的例子一样的东西?

【问题讨论】:

标签: javascript discord


【解决方案1】:

discord.js v13.5.1

const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});

const triggerWords = ['banana', 'fire', 'white'];

client.on('messageCreate', (message) => {
  if (message.author.bot) return false;

  triggerWords.forEach((word) => {
    if (message.content.includes(word)) {
      message.reply(message.content);
    }
  });
});

https://discord.js.org/#/docs/discord.js/stable/class/Client?scrollTo=e-messageCreate

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 2023-04-02
    • 2022-08-19
    • 2017-04-25
    • 1970-01-01
    • 2021-07-05
    • 2018-11-30
    • 2021-10-18
    相关资源
    最近更新 更多