i try make embed
const exampleEmbed = new EmbedBuilder()
.setAuthor({ name: `name : ${name}` })
.setColor(0x0099ff)
.setTitle(`title: ${title}`)
.setDescription(`content : ${content}`)
make embed!!
looking for discordjs14 guide
// Resending a received embed
const receivedEmbed = message.embeds[0];
const exampleEmbed = EmbedBuilder.from(receivedEmbed).setTitle('New title');
channel.send({ embeds: [exampleEmbed] });
----------------------------------------------
// Editing the embedded message content
const exampleEmbed = new EmbedBuilder()
.setTitle('Some title')
.setDescription('Description after the edit');
message.edit({ embeds: [exampleEmbed] });
i try to get message.embed[0]
async execute(interaction) {
...
console.log(interaction.embed[0])
...
}
error:
i hope search title and edit embed...
If you want to send an embed and edit it on an event, You should make thay message a var.
const channel = <client>.channels.cache.get('channel_id');
let message = await channel.send({embeds: [exampleEmbed] });
// editing it
await message.edit({ embeds: [exampleEmbed1] });
Notes: Replace <client> with what you declared your client. it could be client , bot or anything you have declared it.
fist you need to make embed message
const embed = new EmbedBuilder()
.setColor("Your Color")
.setTitle("YourTitle")
.setThumbnail("your google image address")
.setImage("Your Google Image address")
.setDescription("Your Description")
and so much more stuff just type .set or .add it will show you so many of them
and for send the embed
message.reply({embeds : [embed]});
Related
I'm well aware pinging someone with mentions in an embed is impossible, but I still want the blue highlight.
Example:
An image that shows a random bot that is able to mention with blue highlights in an embed that doesn't ping but only mention.
Here's mine, an image that shows my bot that mentions without a blue highlight in an embed.
Here's What I Did:
if(command === 'hug2') {
let targetMember = message.mentions.members.first();
if(!targetMember) return message.reply('you need to mention a user in order to hug them!!');
const exampleEmbed = new EmbedBuilder()
.setTitle(`${message.author.tag} Just Gave <#${targetMember.user.id}> a Hug!`)
.setColor('0x0099FF')
.setImage('http://25.media.tumblr.com/tumblr_ma7l17EWnk1rq65rlo1_500.gif')
.setTimestamp()
.setFooter({ text: 'Made With Horikita Bot!', iconURL: 'https://i.pximg.net/c/250x250_80_a2/img-master/img/2021/01/26/23/55/26/87326371_p0_square1200.jpg' });
message.channel.send({ embeds: [exampleEmbed] });
}
The problem here is probably the fact that you're trying to mention a user in the title of the embed. Try setting the description instead.
if(command === 'hug2') {
let targetMember = message.mentions.members.first();
if(!targetMember) return message.reply('you need to mention a user in order to hug them!!');
const exampleEmbed = new EmbedBuilder()
.setTitle('hug')
.setDescription(`${message.author.tag} Just Gave <#${targetMember.user.id}> a Hug!`)
.setColor('0x0099FF')
.setImage('http://25.media.tumblr.com/tumblr_ma7l17EWnk1rq65rlo1_500.gif')
.setTimestamp()
.setFooter({ text: 'Made With Horikita Bot!', iconURL: 'https://i.pximg.net/c/250x250_80_a2/img-master/img/2021/01/26/23/55/26/87326371_p0_square1200.jpg' });
message.channel.send({ embeds: [exampleEmbed] });
}
I'm not sure of any reason for it to be impossible to mention in an embed's title, but at the very least, this should work.
Hey how do I make the returned message an embed?
return message.reply(`**Here is a list of commands:** \n *Type y!catagory for the commands of the catagory!* \n \n **Economy** \n *y!economy* `);
};
exports.help = {
name: "help",
aliases: ["h"],
usage: "help"
}
You can check v12 embeds guide or v13 embeds guide which can help you
Also some code example:
const embed = new Discord.MessageEmbed()
.setDescription(your_text)
.setTitle("Test Embed")
.setColor("RANDOM");
message.channel.send(embed)
Please note this code is for discord.js v12.x
For v13 you need to use the embeds property
const embed = new Discord.MessageEmbed()
.setDescription(your_text)
.setTitle("Test Embed")
.setColor("RANDOM");
message.channel.send({ embeds: [embed] })
Ive seen many discord embed codes like this:
(This is an old question and im new to coding so...)
const { MessageEmbed } = require('discord.js');
const exampleEmbed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/AfFp7pu.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/AfFp7pu.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/AfFp7pu.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/AfFp7pu.png');
channel.send({ embeds: [exampleEmbed] });
So, what i dont understand is what is the trigger? Like you're supposed to type .ping for pong right? so what do i type to get my bot type this embed?
The way you're sending your embed is(afaik) specific to version 13 of discord.js and you most likely haven't updated discord.js yet:
channel.send({ embeds: [exampleEmbed] });
the version I am currently using is 12.5.3 .
Check your version of discord.js in package.json and if the version is not 13 or above, update or if you want to stick with version 12.5.3 try some of the methods below:
channel.send( exampleEmbed );
Or like this:
channel.send({ embed: exampleEmbed });
Sending the embed like this: "{ embeds: [exampleEmbed] }" makes discord think you are sending an empty message and therefore it doesn't send anything.
This code is meant to be inside an event handler (such as on.message). If that code is already inside an event handler (except for this const { MessageEmbed } = require('discord.js');, it should go at the top), and if it is still not sending, then you should change this line:
channel.send({ embeds: [exampleEmbed] });
to
message.channel.send(exampleEmbed)
There is no trigger in the code sample you provided. You need to have a listener for the message event or interactionCreate event to listen to traditional message-based commands and slash commands. You can pass in handlers into these listeners and respond to command usages.
Since it looks like you're reading the discord.js guide, I would suggest reading from the start, where you would be introduced to how to handle messages first.
To send it, just use a message event. Like this:
const { MessageEmbed, Client } = require('discord.js');
const client = new Client();
client.on('message', msg => {
const { channel, content } = msg;
if(msg.content === 'someCommand') {
const exampleEmbed = new MessageEmbed()
//setProperties...
channel.send({ embeds: [exampleEmbed] });
}
})
client.login('[TOKEN_HERE'])
What's happening here is that the client is receiving a Message object when someone messages (msg). We then use the channel and content properties to evaluate the command, and send the embed if the command is correct. I took out the property settings to save space. You can add them back.
How can I edit an sent embed with my bot? First I contructed an embed:
const countdownEmbed = {
color: 0x0099ff,
title:('Countdown'),
author: {
name:`${user_name}`,
icon_url: `${user_pfp}`,
},
description: 'Your countdown starts in **3 seconds**',
thumbnail: {
url: `${client_pfp}`,
},
timestamp: new Date(),
footer: {
text: `© ${client_name}`,
icon_url: `${client_pfp}`,
},
};
Then I made a new embed:
const countdownEmbed2 = {
title:("New title!"),
description: 'Your countdown starts in **2 seconds**',
};
After creating the "updated" embed I tried to send the message and then edit it after a second:
message.channel.send({ embed: countdownEmbed })
.then((msg)=> {
setTimeout(function(){
msg.edit(countdownEmbed2);
}, 1000)
});
My code only sends the initial embed and does not edit it. But if I change the CountEmbed2 in msg.edit(countdownEmbed2) to a string, it will edit the message itself in Discord, but not the embed. Is there a way to fix this? Or is there an easier way to edit an embed?
I am unsure why but after my test, I concluded that your issue is caused by the way you're writing your embeds.
if you use the MessageEmbed constructor (if you're using discord.js v11 it's RichEmbed) it'll work.
This worked while testing it out:
const countdownEmbed = new MessageEmbed()
.setDescription('test1')
const countdownEmbed2 = new MessageEmbed()
.setDescription('test2')
.setColor('RED')
message.channel.send({ embed: countdownEmbed }).then((msg) => {
setTimeout(function () {
msg.edit(countdownEmbed2);
}, 1000)
})
Here is an example of an edit
const editEmbed = new Discord.MessageEmbed()
.setDescription('this is the old description')
message.channel.send(editEmbed).then((m) =>
m.edit(editEmbed.setDescription('this is the new description')))
let me know if this worked
I have this code:
var datos = ["dato1","dato2","dato3"]
console.log ("》" + message.author.username + " introdujo el comando: " + message.content + " en " + message.guild.name);
let embed = new discord.RichEmbed()
.setTitle("Datos sobre gatos 🐈")
.setColor(12118406)
.setDescription(datos[Math.floor(Math.random() * datos.length)])
.setFooter("© 2018 República Gamer LLC", bot.user.avatarURL)
.setImage("http://i.imgur.com/sYyH2IM.png")
message.channel.send({embed})
.catch ((err) => {
console.error(err);
let embed = new discord.RichEmbed()
.setColor(15806281)
.setTitle("❌ Ocurrió un error")
.setDescription("Ocurrió un error durante la ejecución del comando")
message.channel.send({embed})
})
How can I use a local image path in place of a URL (on the .setImage() line)
Updated Luke's code to Discord.js v12 for anyone else in 2020 who has this same problem
const attachment = new Discord
.MessageAttachment('./card_images/sample.png', 'sample.png');
const embed = new Discord.MessageEmbed()
.setTitle('Wicked Sweet Title')
.attachFiles(attachment)
.setImage('attachment://sample.png');
message.channel.send({embed});
In discord.js v13 and on, MessageEmbed#attachFiles has been deprecated. You should directly add the files into the response from now on.
MessageEmbed#attachFiles has been removed; files should now be
attached directly to the message instead of the embed.
// Before v13
const embed = new Discord.MessageEmbed().setTitle('Attachments').attachFiles(['./image1.png', './image2.jpg']);
channel.send(embed);
// v13
const embed = new Discord.MessageEmbed().setTitle('Attachment').setImage('attachment://image.png');
channel.send({ embeds: [embed], files: ['./image.png'] });
This works for me.
const attachment = new Discord.Attachment('./card_images/sample.png', 'sample.png');
const embed = new RichEmbed()
.setTitle('Wicked Sweet Title')
.attachFile(attachment)
.setImage('attachment://sample.png');
message.channel.send({embed}).catch(console.error)
The other way to do it would be:
const attachment = new Discord.MessageAttachment('./help.png', 'help.png');
message.channel.send({
embed: {
files: [
attachment
],
image: {
url: 'attachment://help.png'
}
}
});
Hello! Unfortunately, Discord's API only accepts URLs and not local paths.
You can only upload your images to a server/image hosting website and get the URL.