TypeError: Cannot read property 'content' of undefined

So i have this code:

const { description } = require("./embed.command");
const { content } = require("discord.js")
const { message } = require("discord.js")
const { Client, Message } = require("discord.js")

module.exports = {
 name: "embed",
 description: "Sending embed ",


 run({ channel }) {

 const args = message.content.split(" ").slice(1);
 
 const embed = new MessageEmbed()
.setTitle("TITLE")
.setDescription(args)
.setColor('RANDOM') 
 message.channel.send(embed)
}
}```

And this error:


```TypeError: Cannot read property 'content' of undefined
 at Object.run (C:\Users\Kamil1\Desktop\GAMES&APPS\team\GucioBOT v2.0\src\commands\embed.command.js:25:26)
 at Client.<anonymous> (C:\Users\Kamil1\Desktop\GAMES&APPS\team\GucioBOT v2.0\src\handlers\command.handler.js:178:11)
 at Client.emit (events.js:327:22)
 at MessageCreateAction.handle (C:\Users\Kamil1\Desktop\GAMES&APPS\team\GucioBOT v2.0\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
 at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Kamil1\Desktop\GAMES&APPS\team\GucioBOT v2.0\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
 at WebSocketManager.handlePacket (C:\Users\Kamil1\Desktop\GAMES&APPS\team\GucioBOT v2.0\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
 at WebSocketShard.onPacket (C:\Users\Kamil1\Desktop\GAMES&APPS\team\GucioBOT v2.0\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
 at WebSocketShard.onMessage (C:\Users\Kamil1\Desktop\GAMES&APPS\team\GucioBOT v2.0\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
 at WebSocket.onMessage (C:\Users\Kamil1\Desktop\GAMES&APPS\team\GucioBOT v2.0\node_modules\ws\lib\event-target.js:125:16)
 at WebSocket.emit (events.js:315:20)```


**Please help!**

This post was flagged by the community and is temporarily hidden.

2 Likes

Firstly, welcome to Glitch @GucioG!

Secondly, by the looks of it, I assume you are very new to the javascript programming language, it looks like you’re having these issues because you don’t know how to debug javascript, I totally understand that this may be very frustrating. I’m going to say something you’re probably not gonna want to hear, but it is the best advice I can give.

Building a Discord bot is really not an easy task, there is so many different things that you have to know about javascript, and how to write good code. There is also advanced topics within discord.js like writing a command handler, interacting with databases and so on.

The best thing I can recommend is not trying to learn how to use discord.js, but how to use javascript. That means don’t try to start with a very hard task like writing a discord.js bot, but start with the easy things like writing a fizzbuzz program. When you are learning a new language there is going to be a lot of reading, doing, failing, doing again, and more failing. This is very repetitive thing when it comes to learning a new language.

I recommend you read on how to learn a new language or framework.

https://hackernoon.com/how-to-learn-a-new-programming-language-faster-dc31ec8367cb

Third, I don’t understand why @internetuser’s post was flagged, it was accurate.

3 Likes

Hi, the problem here is that there is no message for the code to get the channel of - you need to have an event listener for a message, like this:

client.on(‘message’, message => {
const args = message.content.split(" ").slice(1);
const embed = new discord.MessageEmbed()
.setTitle(“TITLE”)
.setDescription(args)
.setColor(‘RANDOM’)
message.channel.send(embed)
});

This should send the embed whenever the bot receives a message. I hope this helps!