Javascript 显示帮助命令的循环

Javascript 显示帮助命令的循环,javascript,arrays,loops,discord.js,Javascript,Arrays,Loops,Discord.js,实际上,我尝试用discord.js创建一个机器人,并尝试执行一个help命令 我不明白为什么我的循环会这样做(我知道这不是一个好方法) 设i=0; const embed=新的RichEmbed(); 如果(参数长度command.help.groups===args.join(“”).toLowerCase()) if(commandsInCategory.size==0){ //如果找不到组,则显示组的用户列表 让commandCategories=bot.commands.map(com

实际上,我尝试用discord.js创建一个机器人,并尝试执行一个help命令

我不明白为什么我的循环会这样做(我知道这不是一个好方法)

设i=0;
const embed=新的RichEmbed();
如果(参数长度<1){
嵌入.setColor('5B4DCA');
while(i
“Modérations”应该显示一个命令,“level&rank”太多,“Outils”4命令和“Sondage”太多


我认为你的解决方法不对。如果您将有超过10个组,机器人将垃圾邮件命令列表。如果
args,则显示所有类别列表。如果args==0尝试查找此类别中的所有命令。对于discord嵌入,您只能添加18个字段,所以如果您在categroy中有超过18个的命令,您将得到api错误。因此,您需要将命令拼接到页面

如果args.length==0或命令组未被罚款,则此代码将显示所有类别。 若组发送嵌入消息的命令在组中(最大10),并作出反应的消息,若页面超过1,所以用户可以改变页面的反应

const{Discord,richembd}=require('Discord.js');
const{prefix,token,classic_roles}=require('../config.json');
const logs=require('../logs/logs');
module.exports.run=async(bot、消息、args)=>{
如果(args.length==0){
//显示用户所有允许的组命令
让commandCategories=bot.commands.map(command=>`!help${command.help.groups}`).过滤器(onlynique).join('\n')//查找所有类别并获取onlynique
让helpMessage=`**命令组列表:*\n\n${commandCategories}`
let Embed=new Discord.RichEmbed()
.setAuthor(message.author.tag、message.author.displayAvatarUrl)
.setDescription(帮助消息)
.setColor(“#e0c40b”)
message.channel.send(嵌入)
}否则{
//尝试查找所需的组
让commandsInCategory=bot.commands.filter(command=>command.help.groups===args.join(“”).toLowerCase())
if(commandsInCategory.size==0){
//如果找不到组,则显示组的用户列表
让commandCategories=bot.commands.map(command=>`!help${command.help.groups}`).过滤器(onlyUnique).连接('\n')
让helpMessage=`**用于获取命令列表使用**\n\n${commandCategories}`
let Embed=new Discord.RichEmbed()
.setAuthor(message.author.tag、message.author.displayAvatarUrl)
.setDescription(帮助消息)
.setColor(“#e0c40b”)
message.channel.send(嵌入)
返回
}
设计数器=0
让allCommands=[]
commandsInCategory.map(命令=>{
allCommands.push({
名称:command.help.name,
描述:command.help.description
})
})
allCommands=GenerateHelpParray(allCommands)
//为了更好地显示,我们将在页面中仅显示10
let Embed=new Discord.RichEmbed()
Embed.setAuthor(message.author.tag、message.author.displayAvatarUrl)
Embed.setDescription(`group:*${args.join('')}**`的list命令)
所有命令[计数器].map(命令=>{
Embed.addField(`**${command.name}**`、`${command.description}`,false)
})
Embed.setColor(“#E8DB0E”)
Embed.setFooter(${allCommands.length}`的`Page${counter+1}})
message.channel.send(嵌入).then(msg=>{
if(allCommands.length<2)返回
//要更改页面,我们将使用react表情符号
味精反应(`◀️`).然后(()=>msg.react()▶️'))
常量过滤器=(反应,用户)=>{
返回[`◀️`, '▶️'].包括(reaction.emoji.name)&&user.id==message.author.id;
};
const collector=msg.createReactionCollector(过滤器,{max:50,time:60000});
收集器.on('collect',(reaction,reactionCollector)=>{
如果(reaction.emoji.name==`◀️`) {
//更改计数器,删除用户反应并调用更改嵌入函数
反应.删除(message.author.id)
计数器-=1
如果(计数器<0)计数器=0
editEmbed(消息、消息、计数器、args.join(“”)、所有命令)
}else if(reaction.emoji.name==`▶️`) {
//更改计数器,删除用户反应并调用更改嵌入函数
反应.删除(message.author.id)
计数器+=1
如果(计数器>=allCommands.length)计数器=allCommands.length-1
editEmbed(消息、消息、计数器、args.join(“”)、所有命令)
}
});
收集器.on('end',(reaction,reactionCollector)=>{
msg.clearReactions()
})
})
}
}
module.exports.help={
姓名:“帮助”,
描述:“你的目标是命令,可接近的目标。”,
访问:“公共”,
小组:“Outils”
}
const onlyUnique=(值、索引、自身)=>{
返回self.indexOf(value)==索引;
}
const editEmbed=(消息、消息、计数器、类别、所有命令)=>