"Rich is not defined" when trying to build an embed - javascript

I made so code to build an embed for my Discord bot, but it doesn't seem to work:
client.on('message', message => {
// Ignore messages that aren't from a guild
if (!message.guild) return;
if (message.content.startsWith('$Commands')) {
let Embed = new Rich.Embed;
let Message = message.guild;
let botEmbed = new Discord.RichEmbed()
.setTitle("Commands From TTB")
.setDescription("**Commands :**")
.setColor("#4dff077")
.setAuthorName("Galak$y#3038")
.setAvatar("https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png")
.addField("1. *Ban* = *Bans User Mentioned After Command* ``$ban <Mention User>``")
.addField("2. Kick = Kicks User Mentioned After Command ``$kick <Mention User>``")
.addField("3. what is myavatar = ``$what is my avatar``")
.addFooter("New Commands Coming Soon...")
return;
message.channel.send(botEmbed)
}
});
Here is the error:

Embeds are created using the RichEmbed class constructor like so:
let embed = new Discord.RichEmbed()
When you declare Embed you're using Rich.Embed, and as it says, Rich is undefined.

Related

Discord.js Avatar command

Hello i am trying to make command to show pfp of mentioned person but i am stuck with that
The code that i am using is this
and has no errors
case 'avatar1':
const user = message.mentions.users.first() || message.author;
const avatarEmbed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setAuthor(user.username)
.setImage(user.avatarURL);
message.channel.send(avatarEmbed);
break;
<User>.avatarURL is a method, therefore it would be <User>.avatarURL()
Documentation: https://discord.js.org/#/docs/main/stable/class/User?scrollTo=avatarURL

making the embed change color during a time discord.js

case 'test':
let timed = "10s"
const tests = new Discord.RichEmbed()
.setTitle("tets")
.setColor('#000000')
message.channel.send(tests);
setTimeout(function(){
tests.setColor('#5e4242')
}, ms(timed));
break;
so im trying to make the embed's color change after 10 secs,this is a test command so its called test.I tried many ways and i searched google and it showed this so i decided to try it and it does completly nothing.I use richembed because when i use messagemebed it says client error
Setting the color after you sent the message will edit the object but it won't edit that message, you can edit the message with the same message object but after changing the color aswell
let timed = "10s"
const tests = new Discord.RichEmbed()
.setTitle("tets")
.setColor('#000000');
var testMsg = message.channel.send(tests).then(
setTimeout(function(){
tests.setColor('#5e4242');
testMsg.edit(tests); // edit the message with the same object but different color
}, ms(timed));
)
break;
You would need to set the message you send into a variable and then edit that message.
let timed = "10s"
const tests = new Discord.RichEmbed()
.setTitle("tets")
.setColor('#000000')
const res = await message.channel.send(tests);
setTimeout(function(){
tests.setColor('#5e4242');
res.edit(tests);
}, ms(timed));
Should also note, await only works in an async function
Here is the V12 version
let embed = new Discord.MessageEmbed()
.setColor('#ffffff')
.setTitle('I am a colour-changing embed')
let msg = await message.channel.send(embed)
setTimeout(() => {
embed.setColor('#5e4242');
msg.edit(embed);
}, /*Delay*/);
This code makes a new embed and then creates a let variable which the message is sent with [kinda like sending the message with a tag]. Then it takes the embed variable edits the color and edits the previous message after a delay.

displayavatarURL when someone joins the server returns always the same error

im trying to make my discord.js bot send an embed when someone joins, with as thumbnail their pfp, but it always leaves the same error.
code:
bot.on('guildMemberAdd', member => {
// Send the message to a designated channel on a server:
const WelcomeChannel = member.guild.channels.cache.find(ch => ch.name === config.WelcomeChannelVar);
var newMember = member
// Do nothing if the channel wasn't found on this server
if (!WelcomeChannel) return;
const welcomeEmbed = new Discord.MessageEmbed()
.setTitle(newMember + 'joined!')
.addField('username', member)
.setColor(0x348a58)
.setThumbnail(newMember.showAvatarURL())
.setFooter('wow very nice profile bro')
WelcomeChannel.send(welcomeEmbed);
member.send("welcome to frogpond! read the rules :)");
});
error:
TypeError: newMember.showAvatarURL is not a function
I've tried everything. can somebody help plz?
thanks!
I'm pretty sure that showAvatarURL() is not a function and you mean avatarURL() instead, so you should change your code to be like this:
const welcomeEmbed = new Discord.MessageEmbed()
// your stuff before thumbnail
.setThumbnail(newMember.user.avatarURL())
// your stuff after thumbnail
edit: the .user is important, because avatarURL is only a User function
It's because you wrote showAvatarURL() instead of displayAvatarURL().

Discord.js - how do I edit message.embed() statements?

I am making a ping command -
It is very simple to code, but I haven't got the slightest idea how to edit the embed I'm using. Here is my code - I'm using a command handler explaining the exports.run statement.
const Discord = require('discord.js')
exports.run = (bot, message, args) => {
const pingUpdate = new Discord.MessageEmbed()
.setColor('#0099ff')
.setDescription('pinging...')
message.channel.send(pingUpdate);
}
exports.help = {
name: 'ping'
}
I need to edit the ping update embed to make the .description edit to perform this (simple ping calculation)
message.channel.send('pinging...').then((m) => m.edit(`${m.createdTimestamp - message.createdTimestamp}ms`))
This would make the description change from 'pinging...' to 'examplepingms'
Thank you in advance
You going right way. But to .setDescription you need create new Embed constructor and add description.
message.channel.send('pinging...').then(msg => {
let embed = new Discord.MessageEmbed() //For discord v11 Change to new Discord.RichEmbed()
.setDescription(`${msg.createdTimestamp - message.createdTimestamp}`)
msg.edit(embed)
})
also, instead of doing msg.createTimeStamp - message.createdTimestamp you could also do bot.ping.toFixed(2)
This should work (dont have time to test rn)
const Embed = new Discord.MessageEmbed()
.setDescription(":one:")
const newEmbed = new Discord.MessageEmbed()
.setDescription(":two:")
// Edit Part Below
var Msg = await message.channel.send(Embed); // sends message
Msg.edit(newEmbed) // edits message with newembed
Edit: realized that im using a older version of discord.js updated to make it work with newer version
Solution seems outdated again, now you should edit embed in message using
Message#edit({embeds:[MessageEmbed#]})
For example:
const oldEmbed = new MessageEmbed();
const messageHandle = await textChannel.send({embeds: [oldEmbed]});
const newEmbed = new MessageEmbed();
messageHandle.edit({embeds:[newEmbed]});
You don't actually have to create a new embed. You can edit the original:
UPDATE: Per the docs, it is recommended to create new embeds, but you use the original embed to pre-populate the new embed. Then, just update what you need and edit the message with the new embed:
// the original embed posted during collected.on('end')
const embed = new MessageEmbed()
.setColor('0xff4400')
.setTitle(`My Awesome Embed`)
.setDescription('\u200b')
.setAuthor(collected.first().user.username, collected.first().user.displayAvatarURL())
.setImage(`https://via.placeholder.com/400x300.png/808080/000000?text=Placeholder`)
.setTimestamp(new Date())
.setThumbnail('https://via.placeholder.com/200x200.png/808080/000000?text=Placeholder');
// In the original embed, I have a placeholder image that the user
// can replace by posting a new message with the image they want
client.on('messageCreate', async message => {
// adding image to original embed
if (message.attachments.size > 0 && !message.author.bot) {
// get all messages with attachments
const messages = await client.channels.cache.get('<CHANNEL>').messages.fetch();
// get the newest message by the user
const d = messages.filter(msg => msg.embeds.length > 0).filter(m => message.author.username === m.embeds[0].author.name).first();
// create new embed using original as starter
const tempEmbed = new MessageEmbed(d.embeds[0])
// update desired values
tempEmbed.setImage(message.attachments.first().url);
// edit/update the message
d.edit({ embeds: [tempEmbed] });
// delete the posted image
message.delete();
}
});

Membercounter won't shows members count

Hi guys I have a problem so when I use the command it should show the number of users but it shows 0. How can i fix it?
Code:
if(command === `${prefix}test`) {
let guild = new Discord.Guild(600811118667235339);
var memberCount = guild.members.filter(member => !member.user.bot).size;
let embed = new Discord.RichEmbed()
.addField("Liczba osob", `${memberCount}`)
message.channel.send(embed)
}
You cannot create a new instance of a Discord.Guild() like this. You need to use something like that:
let guild = message.client.guilds.get("600811118667235339");
It will get the guild which has for ID 600811118667235339.

Categories

Resources