从帮助列表中隐藏nsfw命令

时间:2020-03-16 02:12:21

标签: javascript

对此还没有任何答案。

我正在寻找一种方法来隐藏我为discord.js机器人所拥有的任何nsfw命令。 我希望它仅在完成帮助命令的通道标记为nsfw时显示。

因此,如果该通道标记为nsfw,它将显示nsfw类别和命令。如果未标记为nsfw,则会隐藏nsfw类别和命令。

谢谢你能给我的帮助。

这显示了每个命令及其各自的类别

这是我的帮助命令代码-

const { stripIndents } = require("common-tags");

module.exports = {
    name: "help",
    category: "info",
    description: "Tells you the commads currently able to be used",
    run: async (client, message, args) => {
        if(args[0]){
            return getCMD(client, message, args[0]);
        }else{
            return getALL(client, message);
        }
    }
}

function getALL(client, message){
    const embed = new RichEmbed()
        .setColor("RANDOM")
        .setThumbnail(message.guild.iconURL)

    const commands = (category) => {
        return client.commands
            .filter(cmd => cmd.category === category)
            .map(cmd => `**|-** \`${cmd.name}\``)
            .join("\n");
    }

    const info = client.categories
        .map(cat => stripIndents`**${cat[0].toUpperCase() + cat.slice(1)}** \n${commands(cat)}`)
        .reduce((string, category) => string + "\n" + category);

    return message.channel.send(embed.setDescription(info));
}

function getCMD(client, message, input){
    const embed = new RichEmbed()

    const cmd = client.commands.get(input.toLowerCase()) || client.commands.get(client.aliases.get(input.toLowerCase()));

    let info = `No Information found for command **${input.toLowerCase()}**`;

    if(!cmd){
        return message.channel.send(embed.setColor("#ff0000").setDescription(info));
    }

    if(cmd.name) info = `**Command Name -** ${cmd.name}`;
    if(cmd.aliases) info += `\n**Aliases -** ${cmd.aliases.map(a => `\`${a}\``).join(", ")}`;
    if(cmd.description) info += `**\nDescription -** ${cmd.description}`;
    if(cmd.category) info += `**\nCategory -** ${cmd.category}`;
    if(cmd.usage) {
        info += `**\nUsage -** ${cmd.usage}`
        embed.setFooter(`Syntax <> = Required, [] = Optional`);
    }

    embed.setThumbnail(message.guild.iconURL);

    return message.channel.send(embed.setColor("GREEN").setDescription(info));
}

1 个答案:

答案 0 :(得分:1)

创建排除arr的一种方法,如果命令通道nsfw标志= false,则在此处推送“ nsfw”,然后在过滤器上进行检查。

 const { stripIndents } = require("common-tags");

module.exports = {
    name: "help",
    category: "info",
    description: "Tells you the commads currently able to be used",
    run: async (client, message, args) => {
        if(args[0]){
            return getCMD(client, message, args[0]);
        }else{
            return getALL(client, message);
        }
    }
}

function getALL(client, message){
    let excludeCategoryArr = [];
    if(!message.channel.nsfw) excludeCategoryArr.push('nsfw')
    const embed = new RichEmbed()
        .setColor("RANDOM")
        .setThumbnail(message.guild.iconURL)

    const commands = (category) => {
        return client.commands
            .filter(cmd => cmd.category === category && !excludeCategoryArr.includes(cmd.category))
            .map(cmd => `**|-** \`${cmd.name}\``)
            .join("\n");
    }

    const info = client.categories
        .filter(category => !excludeCategoryArr.includes(category))
        .map(cat => stripIndents`**${cat[0].toUpperCase() + cat.slice(1)}** \n${commands(cat)}`)
        .reduce((string, category) => string + "\n" + category);

    return message.channel.send(embed.setDescription(info));
}

function getCMD(client, message, input){

    const embed = new RichEmbed()

    const cmd = client.commands.get(input.toLowerCase()) || client.commands.get(client.aliases.get(input.toLowerCase()));

    let info = `No Information found for command **${input.toLowerCase()}**`;

    if(!cmd){
        return message.channel.send(embed.setColor("#ff0000").setDescription(info));
    }

    if(cmd.category === 'nsfw' && !message.channel.nsfw) {
        return message.reply('I can`t show NSWF command in not nsfw channel')
    }

    if(cmd.name) info = `**Command Name -** ${cmd.name}`;
    if(cmd.aliases) info += `\n**Aliases -** ${cmd.aliases.map(a => `\`${a}\``).join(", ")}`;
    if(cmd.description) info += `**\nDescription -** ${cmd.description}`;
    if(cmd.category) info += `**\nCategory -** ${cmd.category}`;
    if(cmd.usage) {
        info += `**\nUsage -** ${cmd.usage}`
        embed.setFooter(`Syntax <> = Required, [] = Optional`);
    }

    embed.setThumbnail(message.guild.iconURL);

    return message.channel.send(embed.setColor("GREEN").setDescription(info));
}