目前有一个问题,我收到错误“类型错误:无法读取未定义的‘执行’属性”。我目前正在学习 Javascript,并从测试视频中复制了代码的 pastebin,似乎他的代码在我的编译器上也不起作用。
index.js
const fs = require('fs');
const Discord = require('discord.js');
const bot = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
const { prefix, token } = require('./config.json');
bot.commands = new Discord.Collection();
//File Reading
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
//Command Callbacks
bot.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'queue') {
bot.commands.get('queue').execute(message, args, Discord, bot);
}
})
//Bot is Running
bot.once('ready', () => {
console.log('Good Noodle Bot is online!');
});
//Login
bot.login(token);
queue.js
module.exports = {
name: 'queue',
description: "Begins a Competitive Queue",
async execute(message, args, Discord, bot) {
const channel = '802325198191067146';
const silverRank = ':silver:803746337468186665';
const novaRank = ':nova:803746340009279538';
let embed = new Discord.MessageEmbed()
.setColor('#e42643')
.setTitle('Choose a rank to play with!')
.setDescription('Choosing a rank will begin a queue for that rank!\n\n'
+ `${silverRank} for Silver\n`,
+ `${novaRank} for Nova`);
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(silverRank);
messageEmbed.react(novaRank);
}
}
错误:
TypeError: Cannot read property 'execute' of undefined
at Client.<anonymous> (E:\Visual Studio\Discord\index.js:25:34)
at Client.emit (node:events:379:20)
at MessageCreateAction.handle (E:\Visual Studio\Discord\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (E:\Visual Studio\Discord\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (E:\Visual Studio\Discord\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (E:\Visual Studio\Discord\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (E:\Visual Studio\Discord\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (E:\Visual Studio\Discord\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (node:events:379:20)
at Receiver.receiverOnMessage (E:\Visual Studio\Discord\node_modules\ws\lib\websocket.js:825:20)
答案 0 :(得分:0)
我错误地将命令放在另一个子文件夹 (commands/folder/command.js) 中