【发布时间】:2021-02-13 01:40:01
【问题描述】:
我正在尝试遍历命令文件的文件夹来为不和谐机器人创建帮助命令。 这是我目前的代码。
module.exports = {
name: 'help',
description: 'Lists current commands.',
execute(message) {
//was the first time i made something interesting out of a for loop
if (message.content.toLowerCase() === '$help') {
const commands = 'C:/Bot/commands';
const Discord = require('discord.js');
const helpEmbed = new Discord.MessageEmbed()
.setTitle("Commands")
.setColor(0x6e7175)
.setFooter('Provided by Echo', 'https://cdn.discordapp.com/avatars/748282903997186178/6288e1f487e111b211aa9966c583d948.png?size=128')
.setTimestamp()
for (i of commands) {
let title = i.name
let value = i.description
helpEmbed.addField(title, value)
}
message.channel.send(helpEmbed)
}
}
}
C:/Bot/commands 是存储所有命令的文件夹,此时 i.name 和 i.description 未定义。这里有什么问题?
【问题讨论】:
-
命令结构是什么样的?
标签: javascript node.js iteration discord.js