Reputation: 17
I am very new to javascript and I don't understand a lot of the actual code. However, I have one query, how can I make the "cahbResponses" appear in a MessageEmbed? I've looked at the literature on MessageEmbeds from the Discord JS guides but I still have no clue.
The code I am working on is:
client.on('message', function(message) {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
var args = message.content.substring('!'.length).split(' ');
switch (args[0].toLowerCase()) {
case 'cahb':
var response =
cahbResponses[Math.floor(Math.random() * cahbResponses.length)];
message.channel
.send(response)
.then()
.catch(console.error);
break;
default:
break;
}
});
Upvotes: 0
Views: 1432
Reputation: 6853
First, make sure you are importing Discord
// you probably have this on the beginning of your file
const Discord = require("discord.js");
Then
var response = cahbResponses [Math.floor(Math.random()*cahbResponses .length)];
// Create a MessageEmbed object and set the description
const embed = new Discord.MessageEmbed().setDescription(response);
// Then send the embed
message.channel.send(embed);
Read other MessageEmbed
methods and properties here: https://discord.js.org/#/docs/main/stable/class/MessageEmbed
Upvotes: 2