【发布时间】:2021-04-25 02:43:18
【问题描述】:
我正在尝试在我的不和谐机器人中创建类别,并且我也在尝试创建类别帮助命令,但它运行不正常,所以我需要一些帮助。它不是错误,我的控制台中没有显示任何 DiscordAPIErrors、语法错误或任何错误。它应该在嵌入消息中显示所选类别及其命令,但事实并非如此。它只显示特定命令的帮助,例如,当我输入 (prefix)help kick 时,它会显示 kick 命令帮助,但当我输入 (prefix)help 实用程序时,它只会说提供的命令无效。所以它只对命令而不是类别作出反应。这是我的代码:
代码:
const Discord = require('discord.js')
const fs = require('fs')
const { prefix, owner_id } = require('../../configs.json')
module.exports.run = async (message, args, client) => {
const data = [];
const allCategories = ['general','currency','premium','settings'];
const categoryName = {
"general": 'General Commands',
"currency": 'Currency Commands',
"settings": 'Settings Commands'
}
const user = await client.users.fetch('685079477629485093');
const colors = [
'WHITE','#add8e6','#e0ffff','#d3d3d3',
'#20b2aa','#5d8aa8','#f0f8ff','#f2f3f4',
'#b2beb5','#007fff','#f0ffff','#89cff0',
'#a1caf1','#21abcd','#848482','#bcd4e6',
'#f5f5dc','#318ce7','#ace5ee','#a2a2d0',
'#6699cc','#0d98ba','#0095b6','#e3dac9',
'#0070ff','#1dacd6','#08e8de','#e7feff'
]
const randomColor = colors[Math.round(Math.random()*colors.length)];
if (!args[0]) {
let firstHelp = new Discord.MessageEmbed()
.setColor(randomColor)
.setDescription(`
Commands Usage: \`${prefix}(command)\`\nYou're asking for help,
**${message.author.username}**? I'm here to help!
`, { split: true })
.addFields(
{ name: `⚙️ General`, value: `${(client.generalCommands.map(command =>
`\`${command.help.name}\``).join(', ')) || '\`coming soon...\`'}`, inline: true },
{ name: `???? Currency`, value: `${(client.currencyCommands.map(command =>
`\`${command.help.name}\``).join(', ')) || '\`coming soon...\`'}`, inline: true },
)
.setFooter(`For more information about a specific command, ${prefix}help <command>`)
.setThumbnail(`${message.guild.iconURL({ dynamic: true })}`)
.setTitle(`E-Mod Command List`);
if (!message.guild.iconURL()) {
firstHelp.setThumbnail(`${client.user.displayAvatarURL({ dynamic: true })}`)
}
return message.channel.send(firstHelp)
}
const name = args[0].toLowerCase();
const command = client.generalCommands.get(name)
|| client.generalCommands.find(cmd => cmd.help.aliases && cmd.help.aliases.includes(name))
|| client.currencyCommands.get(name)
|| client.currencyCommands.find(cmd => cmd.help.aliases && cmd.help.aliases.includes(name))
|| client.premiumCommands.get(name)
|| client.premiumCommands.find(cmd => cmd.help.aliases && cmd.help.aliases.includes(name))
if (!command) {
const categorySelected = allCategories.map(category => category.startsWith(name));
if (name == categorySelected) {
let { categoryCommands } = message.client.get(name + 'Commands')
let categoryHelp = new Discord.MessageEmbed()
.setColor(randomColor)
.addFields(
{ name: `${categoryName.map(category => category.startsWith(name))}`, value:
`${(categoryCommands.map(command => `\`${command.help.name}\``).join(', ')) || '\`coming
soon...\`'}`, inline: false },
)
.setFooter(`Premium commands can be used by specific users!`);
return message.channel.send(categoryHelp);
} else {
return message.reply(`it seems you\'ve supplied an invalid command.\nPlease use
\`${prefix}help\` to check out what commands do I support.`)
}
}
let commandHelp = new Discord.MessageEmbed()
.setColor(randomColor)
.addFields(
{ name: 'Description:', value: `${command.help.description}`, inline: false },
{ name: 'Triggers:', value: `${((command.help.aliases).join(', ')) || 'No triggers found'}`,
inline: true },
{ name: 'Usage:', value: `\`${command.help.usage}\``, inline: true },
)
.setFooter(`Premium commands can be used by specific users!`)
.setTitle(`Help | ${command.help.name}`);
return message.channel.send(commandHelp);
}
module.exports.help = {
name: 'help',
description: 'Get a list of all commands or info about a specific command.',
usage: `${prefix}help <command>`,
aliases: ['commands', 'cmds'],
cooldown: 3,
}
【问题讨论】:
-
说起来效果不好。请提供更多信息,包括现在的结果、日志中的任何错误和预期结果。
-
我添加了更多信息。
标签: javascript node.js discord discord.js