【问题标题】:discord.js - command is adding more fields to embeddiscord.js - 命令正在添加更多要嵌入的字段
【发布时间】:2020-12-14 17:27:24
【问题描述】:

当我执行 !commands 时,它会嵌入我给它的 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); 
        }
    });

【问题讨论】:

    标签: javascript discord embed


    【解决方案1】:
    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); 
        }
    });
    

    这是因为您定义了 embed,然后用下一个命令重新定义了它,然后以此类推。试试上面的代码。

    【讨论】:

      猜你喜欢
      • 2020-07-14
      • 2020-10-18
      • 2021-11-07
      • 1970-01-01
      • 2021-07-10
      • 2019-08-21
      • 2020-10-09
      • 2023-03-12
      • 2021-08-20
      相关资源
      最近更新 更多