1
votes

I want to code a bot that will embed a user's sent message in a specific channel. If you know anything about GTA RP servers, it's like a Twitter or Instagram bot.

Here's an example:

screenshot of example embeds

I think it's something about the console.log and the author's name, but I'm not sure so that's why I'm here. How can I embed users' messages like this?

2

2 Answers

1
votes

You can use a MessageEmbed, like programmerRaj said, or use the embed property in MessageOptions:

const {MessageEmbed} = require('discord.js')

const embed = new MessageEmbed()
  .setTitle('some title')
  .setDescription('some description')
  .setImage('image url')

// These two are the same thing
channel.send(embed)
channel.send({embed: {
  title: 'some title',
  description: 'some description',
  image: {url: 'image url'}
}})

To send an embed of users' message in a particular channel, you can do something like this, where client is your Discord.js Client:

// The channel that you want to send the messages to
const channel = client.channels.cache.get('channel id')

client.on('message',message => {
  // Ignore bots
  if (message.author.bot) return
  // Send the embed
  const embed = new MessageEmbed()
    .setDescription(message.content)
    .setAuthor(message.author.tag, message.author.displayAvatarURL())
  channel.send(embed).catch(console.error)
})

Note that the above code will send the embed for every message not sent by a bot, so you will probably want to modify it so that it only sends it when you want it to.

I recommend reading Discord.js' guide on embeds (archive) or the documentation linked above for more information on how to use embeds.

0
votes

What you need i think is :

const Discord = require('discord.js');

const client = new Discord.Client()

client.on("message", async message =>{

    if(message.author.bot) return;
    if(message.channel.id === 'channelID'){
        message.delete();
        const newEmbed = new Discord.MessageEmbed()
        .setAuthor(message.author.tag, message.author.displayAvatarURL())
        .setDescription(`${message.content}`)
        .setColor('#d32256')
        .setImage(message.attachments.first().proxyURL)
        .setTimestamp()
        .setFooter('Instagram', 'ImageOfInsta');
        message.channel.send(newEmbed);
    },
    });

where channelID means : The channel that you want the bot to repost it and ImageOfInsta : an image of instagram logo ! I usually download image or logo first and then re-upload it in Discord.Then i use the link of Discord Image in my codes.

P.S This code works only if you upload an image with a text message!