如何进行设置命令[discord.js]

时间:2018-11-20 04:19:20

标签: discord.js

我正在使用discord.js为机器人发出设置命令:如果需要打开或关闭特定事件,我需要帮助使其设置到允许您选择的位置。
过去一周,我一直在寻找教程,但是没有运气。它应该看起来像这样:

命令示例:!将黑名单设置为开/关

这是我要作为设置命令尝试编写的代码:

bot.on('message', async message => {

  //1 blacklisted words
  let blacklisted = ['fuck', 'shit,', 'bullshit', 'bitch', 'asshole', 'cunt', 'virgin', 'discord.gg'] //words

  //2 looking for words
  let foundInText = false;
  for (var i in blacklisted) { // loops through the blacklisted list
    if (message.content.toLowerCase().includes(blacklisted[i].toLowerCase())) // checks casesensitive words
      foundInText = true;
  }

  //3 deletes and send message
  if (foundInText) {
    message.delete();
    message.channel.send('Hey! That word is not allowed!! :rage:').then(msg => msg.delete(5000));
  }
});

我不希望汤匙进食或其他东西,也许是我做些小事或做一个链接的例子。谢谢您在这里为我提供帮助。我很喜欢。

2 个答案:

答案 0 :(得分:0)

固定代码(对不起,最后一个):

TransactionBuilder

答案 1 :(得分:0)

您也可以尝试

    const blacklist = ['word1', 'word2']; //define the words array
    //check if the message contain atleast one blacklisted word
    if (blacklist.some(word => message.content.toLowerCase().includes(word)){
    //your code
    }
相关问题