当我在做一个不和谐的机器人时,我遇到了这个问题 client.commands.get('embed').execute(message, args, Discord); ^
类型错误:无法读取未定义的属性“执行” 在客户端。 (C:\Users\anton\Desktop\Bot\index.js:29:37) 在 Client.emit (node:events:376:20) 在 MessageCreateAction.handle (C:\Users\anton\Desktop\Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) 在 Object.module.exports [as MESSAGE_CREATE] (C:\Users\anton\Desktop\Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) 在 WebSocketManager.handlePacket (C:\Users\anton\Desktop\Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31) 在 WebSocketShard.onPacket (C:\Users\anton\Desktop\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22) 在 WebSocketShard.onMessage (C:\Users\anton\Desktop\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10) 在 WebSocket.onMessage (C:\Users\anton\Desktop\Bot\node_modules\ws\lib\event-target.js:132:16) 在 WebSocket.emit (node:events:376:20) 在 Receiver.receiverOnMessage (C:\Users\anton\Desktop\Bot\node_modules\ws\lib\websocket.js:825:20)
这是代码:
const client = new Discord.Client();
const prefix = ',';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity('this awesome server', { type: 'WATCHING'}).catch(console.error);
});
client.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 === 'embed'){
client.commands.get('embed').execute(message, args, Discord);
}
if(command === 'version'){
client.commands.get('version').execute(message, args);
}
});
client.login('My token');```
And the command code:
module.exports = {
name: 'version',
description: "this is the version command",
execute(message, args, Discord){
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#e62e1e')
.setTitle('Leon')
.setDescription('Almost Finished')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Something', value: 'Nothing', inline: true },
{ name: 'Something', value: 'Nothing', inline: true },
)
.setTimestamp()
.setFooter('See Leon');
message.channel.send(exampleEmbed)
}
}
答案 0 :(得分:0)
您似乎没有导入 discord.js。
这是怎么做的:把它放在最上面:
const Discord = require('discord.js');