ExcanatorGames
ExcanatorGames

Reputation: 15

How to use an EmbedMessage From a Different File?

I'm having trouble with an embedmessage. I provided my code below of my index.js in which I'm trying to use a function made in "globalspeakfunction.js".

Don't worry about the variables I'm sending they look extra in this but I only provided the relevant code to hopefully reduce confusion.

I'm building up my EmbedMessage in GlobalSpeakFunction.js and then sending it in the channel of the message provided in "index.js".

However my console gives back "cannot send empty message" and when I do a console.log of the EmbedMessage it returns the embed perfectly?

I tried adding a string "test" after my embedmessage in the send() function and then it returned

[object Object]test

I have no idea what's going on here. Am I not able to buildup an EmbedMessage in a different file and then send it back to my bot? Or is there something I'm just overlooking?

index.js

const Discord = require('discord.js');
const client = new Discord.Client();
const speak = require('../GlobalSpeakFunction.js');

client.on('message', message => {
    if (message.content.toUpperCase().includes(`test`)){
        speak("778978295059972106", message, "test", "Default");
    }
}

GlobalSpeakFunction.js

const Discord = require("discord.js")

module.exports = function speak(charID, data, message, emotion){
    var EmbedMessage = new Discord.MessageEmbed()
        .setColor('#0099ff')
        .setTitle('title')
        .setURL('https://discord.js.org/')
        .setDescription(message)
        .setThumbnail('https://drive.google.com/file/d/17J90PzTLBR96wTwk_Wl3U06-or6ZjPW2/view')
        .setTimestamp();
    message.channel.send(EmbedMessage);           
}

Upvotes: 0

Views: 62

Answers (1)

Xeoth
Xeoth

Reputation: 1589

I'm not sure where you experienced the 'Cannot send an empty message' error, I can't reproduce it locally. However, there are a few issues here:

Firstly, you're using toUpperCase() on message.content, and later checking whether it includes (lowercase) "test". Thus, this if statement will never execute.

Secondly, the order of arguments in the speak() function is charID, data, message, emotion, but you're passing them as "778978295059972106", message, "test", "Default" (notice how data and message are swapped when calling the function).

Thirdly, the setThumbnail() function expects a direct link to an image (one that ends with a file extension, like .png or .jpg). You're providing a Google Drive link, which is additionally set to private, which makes it unreadable for anyone but you. I'd recommend uploading it to an image host and getting the direct link from there.

Also, [object Object] is just a string representation of an object. JavaScript tries to convert your MessageEmbed (which is an object) to a string (because you're trying to append 'test' to it).

Upvotes: 1

Related Questions