简体   繁体   中英

Discord.js webhook embed

I was able to make a webhook embed:

let user = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
if (!user) return message.channel.send("Please provide a user!");
const webhook = await message.channel.createWebhook(user.displayName, {
    avatar: user.user.displayAvatarURL(),
    channel: message.channel.id,
});
let embed = new Discord.MessageEmbed()
    .setColor("RANDOM")
    .setTitle(args.join(" ").split("-t")[1].split("-d")[0].trim())
    .setDescription(args.join(" ").split("-d")[1].split("-f")[0].trim())
    .setFooter(args.join(" ").split("-f")[1].split("-i")[0].trim())
    .setImage(args.join(" ").split("-i")[1].split("-th")[0].trim())
    .setThumbnail(args.join(" ").split("-th")[1].trim())
    .setTimestamp();
await webhook.send(embed).then(() => {
    webhook.delete();
});

this is the command format:

?sembed -t <title> -d <description> -f <footer> -i <iamge> -th <thumbnail>

When running the command, it sends nothing if I leave the title/description/footer/image/thumbnail blank.
What should I add or change to make the bot send the embed without completing the format?

try this:

await webhook.send({ embeds: [embed] }).then(() => {
  webhook.delete();
});

This is because discord.jsv13 want to have the content specified for what it is, so it can send it to the client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM