【发布时间】:2021-10-31 12:36:59
【问题描述】:
我正在处理 nuke 命令,但是当我执行命令 ($nuke) 时出现此错误:
(node:3888) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined
这是我的 main.js nuke 命令代码
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'nuke'){
client.commands.get('nuke').execute(message, args);
}
这是我的 nuke.js 代码
const Discord = require('discord.js')
module.exports = {
name: 'nuke',
execute(message) {
if (!message.member.hasPermission('ADMINISTRATOR')) {
message.channel.send('missing permissions')
}
message.channel.clone().then(channel => {
channel.setPosition(message.channel.position)
channel.send('nuked')
})
message.channel.delete()
},
};
错误来自
if(command === 'nuke'){
client.commands.get('nuke').execute(message, args);
}
【问题讨论】:
-
您如何导入/实例化客户端。该错误表明
client.commands是undefined,这意味着client对象上没有属性commands -
client.commands未定义。您是否尝试使用client.commands = new Discord.Collection()、new Collection()或new Map()来定义它?
标签: javascript node.js discord discord.js bots