im nemson
i have a problem with my embed code
this is the code i have for the embed
if (message.content === prefix + "help") {
const embed = new MessageEmbed()
.setTitle("Commandes")
.setColor("#0099ff")
.setDescription(
"**-help** : Affiche les commandes du bot\n" +
"**-ping** : Affiche le ping du bot\n" +
"**-cat** : Affiche une image de chat\n" +
"**-dog** : Affiche une image de chien\n" +
"**-gif** : Affiche un gif random\n" +
"**-anime** : Affiche un gif d'anime\n"
)
.setFooter("Bot de test")
.setTimestamp();
message.channel.send(embed);
}
});
but the problem is that wen i run the comand i get this error ant i dont know how to solv it
Uncaught DiscordAPIError DiscordAPIError: Cannot send an empty message
at DiscordAPIError (c:\Users\user\Documents\receptionist\node_modules\discord.js\src\rest\DiscordAPIError.js:9:5)
at execute (c:\Users\user\Documents\receptionist\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
thx for your help
When you use message.channel.send(embed), discord.js thinks that the embed variable is a string and when it finds out that it isn't, it raises an error. To fix it, all you have to do is change it to:
message.channel.send({ embeds: [embed]})
Related
I'am on a Ionic React project an will like to run USSD code and process the response in other to automate some process.
I first use the react-native-ussd npm package but it sames to not be compatible with ionic react projet (and instead react-native project). Therefore, I got ionic call-number as a functional package for this but I dont know how to get the ussd response to process it. The callNumber() promise function return "Ok" instead of the ussd response.
Can some one help me to resolve this issue?
Thank in avance for your participation.
async handleSubmitForm(e:any) {
e.preventDefault();
this.setState({inProccess: true});
let granted = await AndroidPermissions.checkPermission(AndroidPermissions.PERMISSION.CALL_PHONE)
.then(
isGranted => {
return true;
},
notGranted => {
return false;
}
)
.catch(raison => {
return false;
});
if (granted) {
let res = await CallNumber.callNumber(this.state.ussdCode, false);
prompt(this.state.ussdResponse);
alert(JSON.stringify(res));
}
else {
alert( "Vous n'avez pas donné les autorisations requises. Vous ne pouvez pas utiliser l'application." );
}
this.setState({inProccess: false});
}
I want to create a basic mute command that simply adds a role to the user without a time parameter, how can I implement this in Discord.js v13? I already have slash commands and a handler command setup however I am receiving the following error:
TypeError: Cannot read properties of undefined (reading 'cache')
My Code:
const { SlashCommandBuilder } = require("#discordjs/builders")
const { MessageEmbed } = require("discord.js")
const Discord = require("discord.js")
module.exports = {
data: new SlashCommandBuilder()
.setName("mute")
.setDescription("El bot muteara a un usuario del server")
.addUserOption(option =>
option
.setName("miembro") // target
.setDescription("Mencione al miembro que desea mutear")
.setRequired(true)
)
.addStringOption(option =>
option
.setName("razon") // reason
.setDescription("Razon por la que el usuario sera muteado")
.setRequired(true)
),
async run(client, interaction){
const target = interaction.options.getUser("miembro");
const reason = interaction.options.getString("razon");
if(!interaction.guild.roles.cache.get('902652079762468975')) return interaction.followUp({ embeds: [new MessageEmbed().setColor("RED").setDescription("El rol de muteado no existe")]})
await target.roles.cache.add("902652079762468975");
interaction.followUp({ embeds: [new MessageEmbed().setColor("GREEN").setDescription(`✅ ${target} ha sido muteado. Razon:${reason}`)]})
}
}
Assuming you are on the latest version of djs13, You want to use option.getMember() instead of option.getUser.
getUser returns the User object which does not have any guild information, including roles. getMember returns the GuildMember object which has reference to the roles cache. This will only work if the command is fired from a guild channel.
If you want your command available outside of the guild, you must use getUser and look the user's id up in the guild's member cache manually.
This may require changes to your command registration to accommodate the change in value type.
Documentation
This is the final code
async run(client, interaction){
const target = interaction.options.getMember("miembro");
const reason = interaction.options.getString("razon");
const embed = new Discord.MessageEmbed()
.setColor("GREEN")
.setDescription(`✅ ${target} has been muted. Reason:${reason}`)
await target.roles.add('role-id');
interaction.reply({ embeds: [embed]})
}
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] })
With my Discord bot, I would like to delete a message the client sent after 9 seconds. I have already tried with message.delete([1000]), but this deletes the message sent by the user.
This is my current attempt:
message.channel.send({embed: {
color: 15488557,
title: '❌ Problème dans la commande.',
}});
message.delete([10000])
TextBasedChannel.send() returns a Promise resolving with the Message sent. That means that in your case, you can attach a then() method to use the returned value.
message.channel.send({
embed: {
color: 15488557,
title: '❌ Problème dans la commande.',
}
})
.then(reply => reply.delete(9000))
.catch(console.error);
Your problem is message.delete() this means: delete user message not client(bot) message. You need to do .then(m => m.delete()), good luck!
let embed = new Discord.RichEmbed()
.setTitle('❌ Problème dans la commande.')
.setColor('#hexcode')
message.channel.sendEmbed(embed)
.then(msg => msg.delete(9000)).catch(console.error);
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.