Used EmbedBuilder with sendMessageEmbed



Version: PhantomBot

Summary: Can you create an EmbedBuilder object through Rhino (from Javascript)?

I’m trying to interact with sendMessageEmbed (

public void sendMessageEmbed(String channelName, EmbedObject builder) {
        sendMessageEmbed(getChannel(channelName), builder);

By sending a message from a script with the following information:

$.discordAPI.sendMessageEmbed(channel, new EmbedBuilder().withDescription('test\ntest').withColor(getColor('blue')).build());

Needless to say, the compiler does not recognize the object “EmbedBuilder”

I know you can get sendMessageEmbed to send an embedded message with Description and Color, but I’m trying to use the additional functionality provided in to add titles, urls, and other fun stuff to the embedded message.


Read the section about Working With Java:

You have to create a JavaScript object of the class type and interact with that. You cannot call new Object in-line. For example, if you look at how we implement the JSONStringer from the JSON library:

            JSONStringer =;
            jsonStringer = new JSONStringer();


:pray: Thank you :pray:
Was just a bit lost on where to look, this helps a lot!


No problem. Things are a little wonky with Rhino. Yes, it interacts with Java, but, within the limitations of JavaScript – everything must be a JavaScript object. Basically, you are just making JS objects to interact with of type Java Class. When I think of it in those terms, it makes more sense.

I imagine for what you are doing, you just need to make a EmbedBuilder() JS object and then you can make the call as you are trying to above.


Alright, not to sound rude in asking a bunch of questions (sorry), but I am still slightly confused after reading the Scripting Java page on Rhino.

So what I have now is:

So in order to properly call an external package, you have to add “Packages” to the front, otherwise it won’t recognize the “sx package”
var BUILDERObj =;

Then, in order to create a Javascript object from this class I’ve just pointed to, I do:
var builderObj = new BUILDERObj();

Then the final message:
$.discordAPI.sendMessageEmbed(channel, builderObj.object().withDescription(sendMsg).withColor(getColor(getBlue())).build());

But the error I am receiving is that “Cannot find function object in object [email protected]

Is it because the constructors for the EmbedBuilder class cannot be accessed directly in the way I am doing it right now?

Edit: After swapping the placement of .object(), I received a different error (but I don’t think this is a step in the right direction):

var colorObj = $.discordAPI.getColor(getBlue);
$.discordAPI.sendMessageEmbed(channel, builderObj.withDescription(sendMsg).withColor(colorObj).build().object());

“Cannot find function object in object [email protected]

Edit 2: Fixed by removing object(), it made no sense to interact with this within the Javascript object properties because the Java constructors wouldn’t exist there (right?).

Works as:

var colorObj = $.discordAPI.getColor(getBlue);
$.discordAPI.sendMessageEmbed(channel, builderObj.withDescription(sendMsg).withColor(colorObj).build());

Thank you so much for pointing me in the right direction!


Not rude, I will need to look when I get done with work stuff. Some of the items are better served in the Java core. My guess here is, you are calling getColor() and getBlue(), which Rhino knows nothing about. That might be the function object in object error. [EDIT: Which I see you figured out]

The thing is, the JS has no idea of scope of the Java package, so, trying to call additional methods which make perfect sense from within the Java class do not always work as expected from within Rhino.

Sorry for long delay, I had to take off for a corporate meeting and work remotely from my usual home office for the day.


Check edit 2, I fixed it! :smiley:

getBlue() is a function in my program that returns some rgb value “1, 2 ,3”

No problem, thanks for all the help!

At this point my main focus is maximizing my use of EmbedBuilder and then figuring out the hard stuff with reactions (adding/removing/getting reactions).


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.