'Create an embed message on DiscordJS 13 with Node JS 16 - Discord Bot
How to display the latency of the api, and the bot in an embed message on discordJS with node js 16 Expected result: https://i.imgur.com/DfJ6eVl.png (all in an embed message like this one: https://i.imgur.com/I7T9Rvj.png
I've been trying different things for more than a week, this project is giving me a headache, I've spent my time fixing problems, modifying, deleting, starting again, I'm coming here in the hope to see an END to this command x)
Here is what I have working now : https://i.imgur.com/SYWgGzD.png If need be I show you what I tried but it's not ultra necessary, thanks in advance to all those who could help me!
I checked the guide https://discordjs.guide/popular-topics/embeds.html#using-the-embed-constructor but it didn't help me more to create an embed, I know how to get the data for the latency, but I can't create the embed actually
module.exports = {
name: "ping",
execute(message, args) {
message.channel.send({ content: "Pong." });
},
};
When i do : !ping https://i.imgur.com/jwWYufu.png
Solution 1:[1]
If you're asking how to create a simple embed, you can do that like so:
// const Discord = require('discord.js');
let embed = new Discord.MessageEmbed()
.setAuthor('author name', /* avatar */'https://cdn.discordapp.com/embed/avatars/0.png', '')
.setDescription('description')
.setTitle('title')
.addField('1', 'field 1')
.addField('2', 'field 2', /* inline */ true)
.addField('3', 'field 3', /* inline */ true)
channel.send({embeds: [embed]})
Result:
Don't forget the []! channel.send() expects an object that has at least a content property of type string, or an embeds property of type Discord.MessageEmbed[].
See also the discord.js 13 documentation for info on more things you can add to an embed, like a footer for instance. There's also https://leovoel.github.io/embed-visualizer/, which is a useful tool for building embeds, albeit in json.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ætérnal |

