'Discord.js - how do I edit message.embed() statements?
I am making a ping command - It is very simple to code, but I haven't got the slightest idea how to edit the embed I'm using. Here is my code - I'm using a command handler explaining the exports.run statement.
const Discord = require('discord.js')
exports.run = (bot, message, args) => {
const pingUpdate = new Discord.MessageEmbed()
.setColor('#0099ff')
.setDescription('pinging...')
message.channel.send(pingUpdate);
}
exports.help = {
name: 'ping'
}
I need to edit the ping update embed to make the .description edit to perform this (simple ping calculation)
message.channel.send('pinging...').then((m) => m.edit(`${m.createdTimestamp - message.createdTimestamp}ms`))
This would make the description change from 'pinging...' to 'examplepingms'
Thank you in advance
Solution 1:[1]
You going right way. But to .setDescription you need create new Embed constructor and add description.
message.channel.send('pinging...').then(msg => {
let embed = new Discord.MessageEmbed() //For discord v11 Change to new Discord.RichEmbed()
.setDescription(`${msg.createdTimestamp - message.createdTimestamp}`)
msg.edit(embed)
})
also, instead of doing msg.createTimeStamp - message.createdTimestamp you could also do bot.ping.toFixed(2)
Solution 2:[2]
This should work (dont have time to test rn)
const Embed = new Discord.MessageEmbed()
.setDescription(":one:")
const newEmbed = new Discord.MessageEmbed()
.setDescription(":two:")
// Edit Part Below
var Msg = await message.channel.send(Embed); // sends message
Msg.edit(newEmbed) // edits message with newembed
Edit: realized that im using a older version of discord.js updated to make it work with newer version
Solution 3:[3]
Solution seems outdated again, now you should edit embed in message using
Message#edit({embeds:[MessageEmbed#]})
For example:
const oldEmbed = new MessageEmbed();
const messageHandle = await textChannel.send({embeds: [oldEmbed]});
const newEmbed = new MessageEmbed();
messageHandle.edit({embeds:[newEmbed]});
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 | |
| Solution 2 | |
| Solution 3 | Piotr Wieczorek |
