Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Discord.js TypeError:无法读取属性';执行';未定义/嵌入的类型_Discord.js - Fatal编程技术网

Discord.js TypeError:无法读取属性';执行';未定义/嵌入的类型

Discord.js TypeError:无法读取属性';执行';未定义/嵌入的类型,discord.js,Discord.js,当我在做discord机器人时,我遇到了这个问题:client.commands.get('embed').execute(message,args,discord); ^ TypeError:无法读取未定义的属性“execute” 在客户端。(C:\Users\anton\Desktop\Bot\index.js:29:37) 在Client.emit(节点:事件:376:20) 在MessageCreateAction.handle(C:\Users\anton\Desktop\Bot\no

当我在做discord机器人时,我遇到了这个问题:client.commands.get('embed').execute(message,args,discord); ^

TypeError:无法读取未定义的属性“execute” 在客户端。(C:\Users\anton\Desktop\Bot\index.js:29:37) 在Client.emit(节点:事件:376:20) 在MessageCreateAction.handle(C:\Users\anton\Desktop\Bot\node\u modules\discord.js\src\client\actions\MessageCreate.js:31:14) 在Object.module.exports[作为消息\u CREATE](C:\Users\anton\Desktop\Bot\node\u modules\discord.js\src\client\websocket\handlers\MESSAGE\u CREATE.js:4:32) 在WebSocketManager.handlePacket(C:\Users\anton\Desktop\Bot\node\u modules\discord.js\src\client\websocket\WebSocketManager.js:384:31) 在WebSocketShard.onPacket(C:\Users\anton\Desktop\Bot\node\u modules\discord.js\src\client\websocket\WebSocketShard.js:444:22) 在WebSocketShard.onMessage(C:\Users\anton\Desktop\Bot\node\u modules\discord.js\src\client\websocket\WebSocketShard.js:301:10) 在WebSocket.onMessage(C:\Users\anton\Desktop\Bot\node\u modules\ws\lib\event target.js:132:16) 在WebSocket.emit(节点:事件:376:20) 在Receiver.receiverOnMessage(C:\Users\anton\Desktop\Bot\node\u 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)
    }
}

您似乎没有导入discord.js。
方法如下:将其放在最上面:

const Discord = require('discord.js');

您似乎没有导入discord.js。
方法如下:将其放在最上面:

const Discord = require('discord.js');

您的“命令”文件夹中有哪些文件?您的“命令”文件夹中有哪些文件?