How do I make the returned message a embed? DISCORD.JS - discord.js

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] })

Related

How do I mention a user with the blue highlight in Discord Embed?

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.

discordjs v14 - How to modify embed?

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]});

Discord.Message.Embed is not a constructor

so i tried making an embed. this is the code for it
const Discord = require('discord.js')
//example (inside of a command)
const embed = new Discord.messageEmbed()
embed.setAuthor(`Phaze Bot`)
embed.setTitle(`Commands List`)
embed.setDescription(`$kick: kicks a member \n $ban: bans a member \n $help music: displays music commands \n $help: displays the help screen`)
message.channel.send({embed});
Update so now i got that working, but the bottom line of the code sends
Blockquote
ReferenceError: message is not defined
i now need a fix on this if anyone can help
Put the function inside a on event:
const Discord = require('discord.js')
const client = new Discord.Client();
client.on("message", (message) => {
const embed = new Discord.messageEmbed()
embed.setAuthor(`Phaze Bot`)
embed.setTitle(`Commands List`)
embed.setDescription(`$kick: kicks a member \n $ban: bans a member \n $help music: displays music commands \n $help: displays the help screen`)
message.channel.send(embed);
})
If you want to send the message to specific channel as you mentioned, you would want to use something like this:
client.channels.cache.get(CHANNEL_ID).send(embed)

Bot comes online but the embed won't post on discord

i'm new to programming and started making a discord bot by watching a few tutorials. I want the bot to DM the discord embed to the user who types "-buy" in a text channel. When running the code, the bot comes online and runs the "your bot name is online!" but no DM is sent. I would greatly appreciate any help. Thanks
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
console.log('your bot name is online!');
});
client.on('message', message =>{
if(message.author.client) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLocaleLowerCase();
if(command === 'buy'){
const testEmbed = new Discord.MessageEmbed()
.setColor(0x7f03fc)
.setTitle('test embeddy')
.setDescription('test description woo')
.setFooter('this is the footer')
try {
message.author.send(testEmbed);
} catch {
message.reply('Sorry I cannot message you! Check if your DMs are public!')
}
}
});
client.login('');
the token isn't the problem, i deleted it so i could upload here
The message.author.client returns the bot client, and it doesn't return a boolean. So your bot is blocked from there. Try removing that code and write message.author.bot that returns a boolean if the message author is a bot user. It will work.

How do I use a local image on a discord.js rich embed?

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.

Resources