Embed is very short length compared with other bots - discord

I want to have a very simple command where i make a command and add details with paragraphs.
The output handled by the bot is very weird. I have similar commands with bots from carl bot but in my personal bot it doesnt work.
const Discord = require('discord.js');
let config = require('../config.json');
module.exports = {
name: 'cm',
description: 'Comando',
execute(message, args){
let embed = new Discord.MessageEmbed()
.setColor("#47e10c")
.setDescription(args)
.setFooter(`${config.SERVER_LOGO}`)
message.channel
.send(embed)
}
}
It stays like this
Post in discord

It all depends on how you defined args, we generally define them as
const prefix = "!";
const args = <message>.content.slice(prefix.length).trim().split(/ +/g);
And they return an array of arguments for suppose
// !command hello there would return:
args = ["hello",'there"];
Now to set them as your description in MessageEmbed, you have to join them as a string, you may use array.join() method for the same, so you may do something like this:
const { MessageEmbed } = require ("discord.js");
message.channel.send(new MessageEmbed().setDescription(args.join(" ")));

Related

How to send an embed message to a different channel in interactions?

How to send a separate embed message to a channel different from where the slash command was executed? My current code is the following block.
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, Guild } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('arrest')
.setDescription('puts the member to jail')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to arrest')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason for arrest'))
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction) {
const messageEmbed = new EmbedBuilder()
.setTitle('ARRESTED!')
.setDescription(`***${interaction.options.getUser('target').tag}*** *broke a leg. Oops.*`)
.setColor(0xBD7A21)
.setImage('https://eca.astrookai.repl.co/media/arrest.gif')
await interaction.reply({embeds: [ messageEmbed ]});
},
};
Sending a separate embed object to a different channel is intended for channel logging for moderation actions in the server and I would like to know how to achieve this, thank you.
You can use <channel>.send() for this. In which <channel> is your channel object. You can get the channel in a multiple of different ways but this is probably the easiest:
logChannel = <interaction>.guild.channels.fetch(SNOWFLAKE_ID)
Then, you can send your embed to the logchannel like so:
logChannel.send({ embeds: [YOUR_EMBED] });
To account for every command, the easiest way is to do this in your interactionCreate event
If you need more context, you can check out this example which "logs" an embed to the logChannel.

discord.js | cannot read property 'MessageEmbed' of undefined

I was trying to write in an embed in my discord music bot command to tell the author of the command when and what the bot was playing.
Now, I've tried passing in different arguments (such as messageembed itself) and this isn't working.
I've only been coding for maybe 6 months now, so I'm not the best
here is my code (the bit that I'm having trouble with at least)
const song_queue = queue.get(guild.id);
if (!song) {
song_queue.voice_channel.leave();
queue.delete(guild.id);
return;
}
const stream = ytdl(song.url, {filter: 'audioonly'});
song_queue.connection.play(stream, {seek: 0, volume: 0.5})
.on('finish', () => {
song_queue.songs.shift();
video_player(guild, song_queue.songs[0]);
});
const replyEmbed = new Discord.MessageEmbed()
.setColor('#FF2D00')
.setTitle('🎶 Now Playing 🎶')
.setDescription(`${song.title} [${message.author}]`)
await song_queue.text_channel.send(replyEmbed)
}
It looks like the code that you have is just a snippet taken from your file, but from the error I can assume that Discord has not been defined.
Please make sure to include this at the top of your file:
const Discord = require("discord.js");
It seems you may have forgotten to require discord.js. Do this like so:
const Discord = require('discord.js');
If you have got something that looks like this at the top of the file, but you have a different constant name, i.e. not Discord, replace Discord in Discord.MessageEmbed() with whatever your constant is called.

How do I display local image with discord.js message embed?

I'm working on semi-gacha bot command where you can pull characters and so on. I want to display the characters image after the user pulls and here is where I get stuck, it just doesn't display anything and I found what looked like the answer on here, but it didn't help, as I would get the same result and I don't get any errors, so I don't know what exactly is wrong. I have tried printing out the result of MessageAttachment first:
const attachment = new Discord.MessageAttachment('./chars/1.Jakku.png', '1.Jakku.png');
console.log(attachment);
and I get: undefined, anybody has any ideas of what am I doing wrong? And yes, I have discord.js library imported.
Relevant part of the code:
collector.on('collect', reaction => {
//new embd
const newEmbd = new Discord.MessageEmbed();
// gacha logic
if (reaction.emoji.name === '✅') {
const values = Object.values(chars);
const randomChar = values[parseInt(Math.floor(Math.random()*values.length))];
const attachment = new Discord.MessageAttachment('./chars/1.Jakku.png', '1.Jakku.png');
const charData = randomChar.split('.');
newEmbd
.setTitle(`You pulled: ${charData[1]}!`)
.setColor('YELLOW')
.attachFiles(attachment)
.setImage(`attachment://1.Jakku.png`);
embdReact.edit(newEmbd);
pulled = true;
} else if (reaction.emoji.name === '❌') {
newEmbd
.setTitle('Time for gacha!')
.setColor('YELLOW')
.addFields(
{ name: 'Result:', value: 'You decided against pulling' }
);
embdReact.edit(newEmbd);
};
});
You need to use the correct syntax for attaching files as per this guide
const exampleEmbed = new Discord.MessageEmbed()
.setTitle('Some title')
.attachFiles(['./chars/1.Jakku.png'])
message.channel.send(exampleEmbed);

Guild Members TImeout: Members didn't arrive in time

So I have this command that shows the riches users in a server this command worked yesterday however recently it has stopped working.
const { MessageEmbed } = require("discord.js");
const { stripIndents } = require("common-tags");
const { prefix } = require("../../botconfig.json");
const db = require('quick.db')
let bal = require('../../database/balance');
let rep = require('../../database/rep');
let work = require('../../database/works');
module.exports = {
config:{
name: "rich",
aliases: ["r"],
category: "currency",
description: "Tells who is rich",
usage: ""
},
run: async (client, message, args) => {
// Get all members of the server before doing anything
message.guild.members.fetch().then(guildMembers => {
let board = [];
for (let key of Object.keys(bal)) {
// Checks if the collection of GuildMembers contains the key.
if (guildMembers.has(key)) {
let value = Object.assign({user: guildMembers.get(key).user}, bal[key]);
board.push(value);
}
}
const emojis = [':first_place:', ':second_place:', ':third_place:', ':small_blue_diamond:', ':small_blue_diamond:']
board = board.sort((a,b) => b.balance-a.balance).splice(0, 5);
let top = board.map((x, i) => `${emojis[i]} **${x.balance.toLocaleString()}** - ${x.user.tag}`).join('\n');
let embed = new MessageEmbed()
.setColor("RANDOM")
.addField(`Richest users in **${message.guild.name}**`, `${top}`)
.setFooter('Switch Version 1.1');
return message.channel.send(embed);
}).catch(console.error)
}
}
The error code when the !rich command is used is as follows:
Guild_Members_Timeout: Members didn't arrive in time
I don't know if this is an issue within the bot or if it is an issue with discord.
Okay I have found the answer to my own problem it seems I needed to add intents to my discord bot to fetch the members.
All I did was add this line of code and it worked.
const intents = new Intents([
Intents.NON_PRIVILEGED, // include all non-privileged intents, would be better to specify which ones you actually need
"GUILD_MEMBERS", // lets you request guild members (i.e. fixes the issue)
]);
const client = new Client({ ws: { intents } });
None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out? . In this post it is explained in great detail and that helped me out a lot.TLDR:go to discord developer portal on your particular application ,go to bot , on bot permissions tick whatever is needed and copy the number.Then use this number as a constructor parameter for new Discord.Intents('insert the number here').This worked for me.

How to make Embeds which reads the data from the message?

I am trying to make a Discord bot for announcements. I want to create a command which will read the data from the message and convert it into Embedded message.
An example command: !announce Title, Description, Link, Image
const Discord = require('discord.js');
const bot = new Discord.Client();
//listener
bot.on('ready', () => {
bot.user.setGame('Hello!')
});
bot.on('message', (message) => {
if(message.content == 'text') {
const embed = new Discord.RichEmbed()
.setTitle("Title!")
.setDescription("Description")
.setImage("https://i.imgur.com/xxxxxxxx.png")
.setURL("https://google.com")
.addField("Text", true)
//Nope
.setThumbnail("https://i.imgur.com/Rmiwd1j.png")
.setColor(0x00AE86)
.setFooter("Footer", "https://i.imgur.com/xxxxxxxx.png")
.setTimestamp()
/*
* Blank field, useful to create some space.
*/
message.channel.send({embed});
}});
bot.login('token');
I want Embed to be changed based on the text.
How can I do this?
First, you'll need to detect the command: you can use String.startsWith() to detect !announce:
if (message.content.startsWith('!announce')) {...}
Then you'll have to get the other parts of the command by splitting the string: you can separate them with a comma, as you did (title, description, ...), or with whatever character you want (I'll use a comma in my example).
String.slice() will help you get rid of the !announce part, while String.split() will create an Array with the other parts.
This code will generate an embed like this from the command !announce Title, Description, http://example.com/, http://www.hardwarewhore.com/wp-content/uploads/2018/03/dcord.png
client.on("message", message => {
if (message.content.startsWith('!announce')) {
let rest_of_the_string = message.content.slice('!announce'.length); //removes the first part
let array_of_arguments = rest_of_the_string.split(','); //[title, description, link, image]
let embed = new Discord.RichEmbed()
.setTitle(array_of_arguments[0])
.setDescription(array_of_arguments[1])
.setImage(array_of_arguments[3])
.setURL(array_of_arguments[2])
.addField("Text", true)
.setThumbnail("https://i.imgur.com/Rmiwd1j.png")
.setColor(0x00AE86)
.setFooter("Footer", array_of_arguments[3])
.setTimestamp();
message.channel.send({ embed });
}
});
I suggest using the text instead of the description and remind that the second argument of the .addField() is the text, not the inline value

Resources