Home > Software engineering >  How to get the message content/embed from the message id discord.js?
How to get the message content/embed from the message id discord.js?

Time:10-28

I want to write a command in my own bot that writes the content of the embedded text to a text channel. Unfortunately, so far I've only managed to do it for plain text messages Can someone help me? I am asking for help here because I am a beginner "programmer" and I am clueless. Thank you in advance for your help.

module.exports = {
    name: 'test',
    description: 'test',
    execute (channel, message, Discord) {
    message.channel.messages.fetch("902919303043637269")
        .then(message => message.channel.send(message.content))
        .catch(console.error);
    }
}

CodePudding user response:

You are getting the message correctly, and it has almost all the properties (since it's fetched). You may however want to change message in the .then to something else (since message is already declared). You can access content and embeds with these 2 properties:

Here is an example logging the content and embeds:

message.channel.messages.fetch("902919303043637269")
.then(msg => {
  console.log(msg.content)
  console.log(msg.embeds)
})
  • Related