Reputation: 116
I am making a bot to manage my everyday tasks as a fun project. but I am stuck here:
TypeError: Cannot read property 'MessageEmbed' of undefined
I can't seem to find an answer that fits what I need. Here is my code:
client.on('message', message => {
if (message.content.startsWith('t!test')) {
const embed = new Discord.MessageEmbed()
.setTitle("This is a title")
.setDescription("This is a description")
.setTimestamp()
.setFooter("This is a footer")
.setAuthor("This is the author's name")
.addField("This is a field", "this is its description")
.setImage("https://images-ext-2.discordapp.net/external/cC-YBJkH2GXnX7MHMASUM9Gle1S1im3rDJj2K54A28w/%3Fcid%3D73b8f7b19a5ccc575679c0a7fc4a673b753e4ce993f35223%26rid%3Dgiphy.mp4/https/media2.giphy.com/media/Q8bEDnj9hZd6vivXSZ/giphy.mp4")
.setThumbnail("https://images-ext-2.discordapp.net/external/cC-YBJkH2GXnX7MHMASUM9Gle1S1im3rDJj2K54A28w/%3Fcid%3D73b8f7b19a5ccc575679c0a7fc4a673b753e4ce993f35223%26rid%3Dgiphy.mp4/https/media2.giphy.com/media/Q8bEDnj9hZd6vivXSZ/giphy.mp4")
message.channel.send(embed)
}
});
Any help will be appreciated as I have been stuck on this problem for the pas 3 hours.
EDIT: I fixed the error! Here is the code for anyone who is having this problem:
require('dotenv').config();
const { MessageEmbed, Client } = require('discord.js');
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Bot logged in as ${client.user.tag}`)
});
client.on('message', message => {
if (message.content.startsWith('t!test')) {
const embed = new Discord.MessageEmbed()
.setTitle("This is a title")
.setDescription("This is a description")
.setTimestamp()
.setFooter("This is a footer")
.setAuthor("This is the author's name")
.addField("This is a field", "this is its description")
.setImage("https://images-ext-2.discordapp.net/external/cC-YBJkH2GXnX7MHMASUM9Gle1S1im3rDJj2K54A28w/%3Fcid%3D73b8f7b19a5ccc575679c0a7fc4a673b753e4ce993f35223%26rid%3Dgiphy.mp4/https/media2.giphy.com/media/Q8bEDnj9hZd6vivXSZ/giphy.mp4")
.setThumbnail("https://images-ext-2.discordapp.net/external/cC-YBJkH2GXnX7MHMASUM9Gle1S1im3rDJj2K54A28w/%3Fcid%3D73b8f7b19a5ccc575679c0a7fc4a673b753e4ce993f35223%26rid%3Dgiphy.mp4/https/media2.giphy.com/media/Q8bEDnj9hZd6vivXSZ/giphy.mp4")
message.channel.send(embed)
}
});
client.login(process.env.token)
(The embed is an example..)
Upvotes: 1
Views: 406
Reputation: 656
Try defining Discord before new Discord.MessageEmbed()
: const Discord = require('discord.js');
Upvotes: 1