简体   繁体   English

discord.js - 命令正在添加更多要嵌入的字段

[英]discord.js - command is adding more fields to embed

When i do !commands, it makes an embed with the 5 fields i gave it when i do it again, it adds the 5 fields to the next embed making it 10, then 15, then 20. How do i stop this?当我执行命令时,它会嵌入我给它的 5 个字段,当我再次执行时,它将 5 个字段添加到下一个嵌入中,使其成为 10,然后是 15,然后是 20。我如何停止这个?

const Embed = new discord.MessageEmbed()
const discord = require("discord.js");
const client = new discord.Client();

client.on("message", message => {
        if (message.content === "!commands") {
            cmdEmbed
                .setTitle("Bot Commands")
                .setColor(0xff0000)
                .addField("!website", "Brings up the official website")
                .addField("!botinfo", "See who helped and made the bot.")
                .addField("!schedule", "Brings up the Schedule")
                .addField("!calendar", "Brings up the Calendar")
                .addField("!whitecalendar", "Brings up the White calendar ")
                .setFooter("Commands");
    
            message.channel.send(Embed); 
        }
    });
const discord = require("discord.js");
const client = new discord.Client();

client.on("message", message => {
    if (message.content === "!commands") {
        const Embed = new discord.MessageEmbed()
            .setTitle("Bot Commands")
            .setColor(0xff0000)
            .addField("!website", "Brings up the official website")
            .addField("!botinfo", "See who helped and made the bot.")
            .addField("!schedule", "Brings up the Schedule")
            .addField("!calendar", "Brings up the Calendar")
            .addField("!whitecalendar", "Brings up the White calendar ")
            .setFooter("Commands");
        message.channel.send(Embed); 
    }
});

It's because you defined embed, the redefined it again with the next command, then so on and so forth.这是因为您定义了嵌入,然后使用下一个命令重新定义了它,然后依此类推。 Try the code above.试试上面的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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