1
votes

this following code used to work but for some reason it no longer works i have no clue why this is the code followed by the error message

module.exports = {
    name:  'stats',
    description: "This list shows the stats of the lol players",
    execute(message, args, Discord) {
       const newEmbed = new Discord.MessageEmbed()
       .setColor('#304281')
       .setTitle('League of Legends Stats')

       .setDescription('This is a list that shows you who has their stats coded into the bot, just copy and paste the command :)')
       .addFields({name: 'X', value: 'Y'},)
       .setImage('https://candid.technology/wp-content/uploads/2019/10/League-of-Legends-Wallpaper-5.jpg')
       .setFooter('if the stats seem wrong just click on update :)');

       message.channel.send(newEmbed)
    }
}
(node:2540) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'MessageEmbed' of undefined
    at Object.execute (C:\Users\A_AlA\Desktop\Aegir2\commands\stats.js:5:37)
    at Client.<anonymous> (C:\Users\A_AlA\Desktop\Aegir2\main.js:138:42)
    at Client.emit (events.js:315:20)
    at MessageCreateAction.handle (C:\Users\A_AlA\Desktop\Aegir2\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\A_AlA\Desktop\Aegir2\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\A_AlA\Desktop\Aegir2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\A_AlA\Desktop\Aegir2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\A_AlA\Desktop\Aegir2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\A_AlA\Desktop\Aegir2\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)
(node:2540) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

1
How do you call execute()? Can you add it to your question? - Zsolt Meszaros

1 Answers

1
votes

There are a two reasons I can think of as to why this might not be working as you anticipated. I'm assuming the following are true:

  • The code is in a separate file but the execute function is called on the file called "main.js"
  • The code provided is the only code on the file

Discord is not being passed in the function properly

When you call the "execute" function on the message event in the main.js file, chances are you aren't passing in all three variables. This would result in Discord not being passed in as well, so, in the index.js file, this is what your execute function should look like

execute(message, args, Discord)

This will supply your code with the proper variables to function. However, do note that you would need to update your code on the command as well to the same exact thing so that all variables are passed received correctly

Discord is undefined

Judging by the error, I believe that this one is the most likely one out of my two reasons why. I highly recommend doing thing even if this isn't an error because it's a good practice if you add more packages.

In my assumptions, I assume that you do not define Discord at the top of the code. Therefore, Discord isn't defined and a MessageEmbed isn't created because it can't get the Discord package. Add this above the modules.export

const { Discord } = require("discord.js");

Remember, once you do this, you do not have to redefine the client. You have already passed it as an argument in execute()