Javascript TypeError:无法读取属性';执行';discord.js中未定义的

Javascript TypeError:无法读取属性';执行';discord.js中未定义的,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,编辑:此问题已解决 我在尝试执行时遇到以下错误!鱼群指挥不和谐: TypeError: Cannot read property 'execute' of undefined at Client.<anonymous> (C:\Users\shane\Desktop\DiscordBot\main.js:38:43) at Client.emit (events.js:315:20) at MessageCreateAction.handle (C:\User

编辑:此问题已解决

我在尝试执行时遇到以下错误!鱼群指挥不和谐:

TypeError: Cannot read property 'execute' of undefined
    at Client.<anonymous> (C:\Users\shane\Desktop\DiscordBot\main.js:38:43)
    at Client.emit (events.js:315:20)
    at MessageCreateAction.handle (C:\Users\shane\Desktop\DiscordBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\shane\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\shane\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\shane\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\shane\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\shane\Desktop\DiscordBot\node_modules\ws\lib\event-target.js:125:16)
    at WebSocket.emit (events.js:315:20)
    at Receiver.receiverOnMessage (C:\Users\shane\Desktop\DiscordBot\node_modules\ws\lib\websocket.js:797:20)
fish.js:

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

// embeds that are picked at random
const rawFish = new Discord.MessageEmbed()
.setColor('#0077be')
.setTitle('You caught a raw fish!')
.setDescription('It has been added to your backpack.')
.setThumbnail('https://vignette.wikia.nocookie.net/minecraft-computer/images/7/77/Raw_Fish.png/revision/latest/scale-to-width-down/340?cb=20130815172634')

const rawSalmon = new Discord.MessageEmbed()
.setColor('#0077be')
.setTitle('You caught a raw salmon!')
.setDescription('It has been added to your backpack.')
.setThumbnail('https://vignette.wikia.nocookie.net/minecraft/images/f/fd/RawSalmonOldTexture.png/revision/latest/window-crop/width/200/x-offset/0/y-offset/0/window-width/201/window-height/200?cb=20200519072953')

const pufferfish = new Discord.MessageEmbed()
.setColor('#0077be')
.setTitle('You caught a pufferfish!')
.setDescription('It has been added to your backpack.')
.setThumbnail('https://static.wikia.nocookie.net/minecraft_gamepedia/images/0/02/Pufferfish_%28item%29_JE5_BE2.png/revision/latest/scale-to-width-down/150?cb=20191230044452')

const tropicalFish = new Discord.MessageEmbed()
.setColor('#0077be')
.setTitle('You caught a tropical fish!')
.setDescription('It has been added to your backpack.')
.setThumbnail('https://static.wikia.nocookie.net/minecraft_gamepedia/images/a/ad/Tropical_Fish_JE2_BE2.png/revision/latest/scale-to-width-down/150?cb=20191230044408')

const fishTypes = [rawFish, rawSalmon, pufferfish, tropicalFish];

module.exports = {
    name: 'fishCommand',
    description: "Lets the user fish",
    execute(message, args){

        //sends a random embed from fishTypes
        message.channel.send(fishTypes[Math.floor(Math.random() * fishTypes.length)]);
        
       
        }
    }

    var backpack = 0;

 module.exports = {
    name: 'backpack',
    description: "Lets the user see their backpack",
    execute(message, args){

        message.channel.send('Your backpack has ' + backpack + ' fish in it.');
           
            }
        }
您的命令文件(fish.js)名称应与客户端获得的文件相同。

client.commands.get('fishCommand').execute(消息,args);
文件名应该是'fishCommand.js',或者您应该将其写成
get('fish')

client.commands.get('fish').execute(message,args);

execute
未定义,因为您的客户端不知道它位于何处。

实际上,集合中的每个命令都映射了文件中
name
属性中的命令名作为键;文件名不是问题。谢谢,我感谢您的帮助,但这似乎并没有解决问题。正如您所说,我将该文件重命名为“fishCommand.js”,但仍然出现相同的错误。关于可能导致这种情况的原因还有什么其他想法吗?@Lioness100好吧,我对javascript的了解不多,我也不是一个专业的lol。Dashanesta你能试着删除执行
背包
命令的
模块。exports
?然后为
背包
命令创建一个文件。@Hons谢谢你的建议,我今天晚些时候有机会的时候会尝试。这已经解决了问题!谢谢你们,我真的很感谢你们的帮助!
const Discord = require('discord.js');

// embeds that are picked at random
const rawFish = new Discord.MessageEmbed()
.setColor('#0077be')
.setTitle('You caught a raw fish!')
.setDescription('It has been added to your backpack.')
.setThumbnail('https://vignette.wikia.nocookie.net/minecraft-computer/images/7/77/Raw_Fish.png/revision/latest/scale-to-width-down/340?cb=20130815172634')

const rawSalmon = new Discord.MessageEmbed()
.setColor('#0077be')
.setTitle('You caught a raw salmon!')
.setDescription('It has been added to your backpack.')
.setThumbnail('https://vignette.wikia.nocookie.net/minecraft/images/f/fd/RawSalmonOldTexture.png/revision/latest/window-crop/width/200/x-offset/0/y-offset/0/window-width/201/window-height/200?cb=20200519072953')

const pufferfish = new Discord.MessageEmbed()
.setColor('#0077be')
.setTitle('You caught a pufferfish!')
.setDescription('It has been added to your backpack.')
.setThumbnail('https://static.wikia.nocookie.net/minecraft_gamepedia/images/0/02/Pufferfish_%28item%29_JE5_BE2.png/revision/latest/scale-to-width-down/150?cb=20191230044452')

const tropicalFish = new Discord.MessageEmbed()
.setColor('#0077be')
.setTitle('You caught a tropical fish!')
.setDescription('It has been added to your backpack.')
.setThumbnail('https://static.wikia.nocookie.net/minecraft_gamepedia/images/a/ad/Tropical_Fish_JE2_BE2.png/revision/latest/scale-to-width-down/150?cb=20191230044408')

const fishTypes = [rawFish, rawSalmon, pufferfish, tropicalFish];

module.exports = {
    name: 'fishCommand',
    description: "Lets the user fish",
    execute(message, args){

        //sends a random embed from fishTypes
        message.channel.send(fishTypes[Math.floor(Math.random() * fishTypes.length)]);
        
       
        }
    }

    var backpack = 0;

 module.exports = {
    name: 'backpack',
    description: "Lets the user see their backpack",
    execute(message, args){

        message.channel.send('Your backpack has ' + backpack + ' fish in it.');
           
            }
        }