javascript - 从帮助列表中隐藏 nsfw 命令
问题描述
还没有看到任何答案。
我正在寻找一种方法来隐藏我的 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));
}
解决方案
一种创建排除 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));
}
推荐阅读
- google-analytics - 自定义报告维度钻取中的 Google Analytics(分析)数据丢失
- go - 在 Golang 中实现可跟踪并发的最佳方法
- javascript - 过滤器不像我在 js 中理想化的方式那样工作
- php - 这个 CURL 错误是什么意思:OpenSSL SSL_read: No error
- tensorflow - 如何在任何深度建模框架中实现以均值和方差值作为输入的高斯渲染器(需要可反向传播)
- sql - 包含短语的转义参数
- python - 如何将列表从一个函数传递到另一个函数?
- javascript - 获取 Cesium3DTileset 中特征的几何图形
- python - 在 jupyter 笔记本/终端中执行 cdo(气候数据操作员)包中的命令时出现问题
- swift - 如何水平对齐状态栏项目文本?