gpt4 book ai didi

javascript - 从帮助列表中隐藏 nsfw 命令

转载 作者:行者123 更新时间:2023-11-28 03:04:44 25 4
gpt4 key购买 nike

还没有看到任何答案。

我正在寻找一种方法来隐藏我的 Discord.js 机器人的任何 nsfw 命令。我希望它仅在执行帮助命令的 channel 标记为 nsfw 时显示。

因此,如果 channel 标记为 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 的一种方法,如果命令 channel nsfw flag = 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));
}

关于javascript - 从帮助列表中隐藏 nsfw 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60699542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com