【发布时间】:2021-07-03 18:53:38
【问题描述】:
我有一个不和谐的音乐机器人,它有很多功能。我做了一个setprefix 命令,它首先运行得非常完美,然后help 出现错误。错误是:
TypeError: Cannot read property 'name' of undefined
我不知道该怎么做,谁能帮助我?
help.js:
const { MessageEmbed } = require('discord.js')
module.exports = {
info: {
name: "help",
description: "To show all commands",
usage: "[command]",
aliases: ["commands", "help me", "pls help"]
},
execute(client, message, args){
var allcmds = "";
client.commands.forEach(cmd => {
let cmdinfo = cmd.info
allcmds+="``"+message.client.prefix+cmdinfo.name+" "+cmdinfo.usage+"`` ~ "+cmdinfo.description+"\n"
})
let embed = new MessageEmbed()
.setAuthor("Commands of "+client.user.username, "https://raw.githubusercontent.com/SudhanPlayz/Discord-MusicBot/master/assets/Music.gif")
.setColor("BLUE")
.setDescription(allcmds)
.setFooter(`To get info of each command you can do ${client.config.prefix}help [command] and my prefix is % | Hander by Lavaboy0192#2014`)
if(!args[0])return message.channel.send(embed)
else {
let cmd = args[0]
let command = client.commands.get(cmd)
if(!command)command = client.commands.find(x => x.info.aliases.includes(cmd))
if(!command)return message.channel.send("Unknown Command")
let commandinfo = new MessageEmbed()
.setTitle("Command: "+command.info.name+" info")
.setColor("YELLOW")
.setDescription(`
Name: ${command.info.name}
Description: ${command.info.description}
Usage: \`\`${client.config.prefix}${command.info.name} ${command.info.usage}\`\`
Aliases: ${command.info.aliases.join(", ")}
`)
message.channel.send(commandinfo)
}
}
}
setprefix 命令:
module.exports = {
name: "setprefix",
description: "Sets the prefix for the bot",
argsNumber: 1,
usage: "<prefix>",
execute(message, args){
const prefix = args.shift();
message.client.prefixes.set(message.guild.id, prefix);
message.reply(`Prefix set to ${prefix}`);
}
}
【问题讨论】:
标签: javascript node.js discord.js