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:
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?
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:
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?
-
You can create a
MessageEmbed
. discord.js/#/docs/main/stable/class/MessageEmbed – programmerRaj Commented Sep 26, 2020 at 2:14
3 Answers
Reset to default 8You 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')
// Discord.js v13
// These two are the same thing
channel.send({embeds: [embed]})
channel.send({
embeds: [{
title: 'some title',
description: 'some description',
image: {url: 'image url'}
}]
})
// Discord.js v12
// 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({embeds: [embed]}).catch(console.error)
// Discord.js v12:
// 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 remend reading Discord.js' guide on embeds (archive) or the documentation linked above for more information on how to use embeds.
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!
Here this link leads you to an online embed tool that automatically creates Discord embeds according to your wishes and ideas. this could certainly help you.
Just try this: -> https://autocode./tools/discord/embed-builder/