Skip to content
Advertisement

How to respond with embeds

Currently I am trying to work on my bot and update its responses. Right now I am trying to use the code below to make it respond with the random embeds I made. For some reason when doing using this code the bot either responds with “NaN” or “3”?

JavaScript

Advertisement

Answer

The purpose of:

JavaScript

Is to generate a pseudo-random integer between 0 and the length of the array (floored). This does not provide a random element from an array. You can use this number to get an element from an array using bracket syntax.

JavaScript

Edit:

You’ll have to understand template literals to realize why your bot is sending [object Object]. Template literals (${variable}) are mainly used for two purposes

  • To merge together a string and variable, or multiple variables
  • To coerce a variable’s data type to a string

Here’s an example of the second purpose.

JavaScript

Why is this important? orangeinfocommandembed, for example, is an instance of the MessageEmbed class. So when that gets coerced to a string, it becomes [object Object].

JavaScript

Sorry, that’s a long explanation for a relatively easy fix. Just remove the template literals and only use the base variables.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement