【问题标题】:BlackListing Command黑名单命令
【发布时间】:2021-03-01 03:16:20
【问题描述】:

我正在使用 discord.js 创建一个不和谐机器人,但我对 javascript 有点陌生,更习惯于 C#。我的机器人有问题,我正在尝试将单词列入黑名单并且我能够做到,但是我遇到了一个错误,并且当我发送带有列入黑名单的单词的命令时;命令执行,但我不希望这种情况发生,所以我需要它来读取命令并检查命令内容中是否包含列入黑名单的单词。

 if(config.FILTER_LIST.some(word => message.content.toLowerCase().includes(word))){

        const listEmbed = new Discord.RichEmbed()
        .setColor("EBE306")
        .setTitle(`**BlackListed**`)
        .setDescription(`**This Word blacklisted**`)
        .setFooter(`Reaper`)
        message.channel.send(listEmbed);
      
        function dohelp() {
            const helpEmbed = new Discord.RichEmbed()
            .setColor("EBE306")
            .setTitle(`Help Menu`)
            .setDescription(``)
            .setFooter(`Reaper`)
            message.channel.send(helpEmbed);
          }

    }

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    我假设您的代码结构如下:

    client.on('message', message =>{
           if(config.FILTER_LIST.some(word => message.content.toLowerCase().includes(word))){
    
            const listEmbed = new Discord.RichEmbed()
            .setColor("EBE306")
            .setTitle(`**BlackListed**`)
            .setDescription(`**This Word blacklisted**`)
            .setFooter(`Reaper`)
            message.channel.send(listEmbed);
          
            function dohelp() {
                const helpEmbed = new Discord.RichEmbed()
                .setColor("EBE306")
                .setTitle(`Help Menu`)
                .setDescription(``)
                .setFooter(`Reaper`)
                message.channel.send(helpEmbed);
              }
    
        }
    // do the command.
    }
    

    在这种情况下,您只需要在 if 语句的末尾添加一个 return 语句(参见下面的代码)。 如果我误解了您的问题,请在下方留言。

    client.on('message', message =>{
    if(config.FILTER_LIST.some(word => message.content.toLowerCase().includes(word))){
    
            const listEmbed = new Discord.RichEmbed()
            .setColor("EBE306")
            .setTitle(`**BlackListed**`)
            .setDescription(`**This Word blacklisted**`)
            .setFooter(`Reaper`)
            message.channel.send(listEmbed);
          
            function dohelp() {
                const helpEmbed = new Discord.RichEmbed()
                .setColor("EBE306")
                .setTitle(`Help Menu`)
                .setDescription(``)
                .setFooter(`Reaper`)
                message.channel.send(helpEmbed);
              }
              return;
        }
    // run the command.
    }
    

    【讨论】:

    • 我厌倦了,命令仍然通过我只是希望它说单词已被列入黑名单而不是帮助菜单这里是我尝试的照片cdn.discordapp.com/attachments/774057854788567050/…
    • 您将不得不向我们展示更多代码,例如您在何处以及如何调用命令...
    猜你喜欢
    • 2019-02-23
    • 2021-04-08
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 2016-12-30
    • 2021-04-16
    • 2017-04-21
    • 2020-01-22
    相关资源
    最近更新 更多