[英]Discord.js Error - TypeError: Cannot read property 'execute' of undefined
[英]TypeError: Cannot read property 'execute' of undefined (Discord.js)
目前有一個問題,我收到錯誤“TypeError:無法讀取未定義的'執行'的屬性”。 我目前正在學習 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);
隊列.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)
我錯誤地將命令放在另一個子文件夾(commands/folder/command.js)中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.