TypeError: MessageEmbed is not a constructor

huangapple go评论62阅读模式
英文:

TypeError: MessageEmbed is not a constructor

问题

我有这段代码,它计算一个板条箱,然后将总值放入一个嵌入式消息

这是代码:

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js')

const normalMelonValue = 9600;
const normalPineappleValue = 11520;
const LargeMelonValue = 27000;
const LargePineappleValue = 31050;

module.exports = {
    data: new SlashCommandBuilder()
        .setName('crate')
        .setDescription('Crate Calculator')
        .addStringOption(option =>
            option.setName('type')
                .setDescription('The Type of the crate')
                .setRequired(true)
                .addChoices({ name: "Normal", value: "normal" })
                .addChoices({ name: "Large", value: "large" })
        )
        .addStringOption(option =>
            option.setName('item')
                .setDescription('The item to calculate')
                .setRequired(true)
                .addChoices({ name: "Melon", value: "melon" })
                .addChoices({ name: "Pineapple", value: "pineapple" })
        )
        .addIntegerOption(option =>
            option.setName('amount')
                .setDescription('The amount of the item to calculate')
                .setRequired(true),
        ),
    async execute(interaction) {
        const crateSize = interaction.options.getString('type');
        const item = interaction.options.getString('item');
        const amount = interaction.options.getInteger('amount');

        let totalValue = 0;
        if (crateSize === 'normal') {
            if (item === 'melon') {
                totalValue = normalMelonValue * amount;
            } else if (item === 'pineapple') {
                totalValue = normalPineappleValue * amount;
            }
        } else if (crateSize === 'large') {
            if (item === 'melon') {
                totalValue = LargeMelonValue * amount;
            } else if (item === 'pineapple') {
                totalValue = LargePineappleValue * amount;
            }
        }

        const embed = new MessageEmbed()
            .setColor('#0099ff')
            .setTitle(`Crate Calculated - ${crateSize} ${item} crate`)
            .addFields(
                { name: 'Amount', value: `${amount} ${item} crates`, inline: true },
                { name: 'Total Value', value: `$${totalValue}`, inline: true },
            )
            .setTimestamp()
            .setFooter('calculated successfully')

        await interaction.reply({ embeds: [embed] })
    },
};

每次我尝试修复它,当我执行代码时都会遇到这个错误:

TypeError: MessageEmbed is not a constructor
    at Object.execute (C:\Users\Dell\Desktop\bot\commands\fun\crates.js:52:23)
    at Object.execute (C:\Users\Dell\Desktop\bot\events\interactionCreate.js:16:18)
    at Client.<anonymous> (C:\Users\Dell\Desktop\bot\index.js:35:44)
    at Client.emit (node:events:512:28)
    at InteractionCreateAction.handle (C:\Users\Dell\Desktop\bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
    at module.exports [as INTERACTION_CREATE] (C:\Users\Dell\Desktop\bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)

我试图修复它,但它不起作用,我尝试了我知道的但我总是遇到这个错误,你能帮我吗?
谢谢你的帮助。

英文:

I have this code it calculates a crate then puts the total value in an embed

Here is the code:

const { SlashCommandBuilder } = require(&#39;@discordjs/builders&#39;);
const { MessageEmbed } = require(&#39;discord.js&#39;)
const normalMelonValue = 9600;
const normalPineappleValue = 11520;
const LargeMelonValue = 27000;
const LargePineappleValue = 31050;
module.exports = {
data: new SlashCommandBuilder()
.setName(&#39;crate&#39;)
.setDescription(&#39;Crate Calculator&#39;)
.addStringOption(option =&gt;
option.setName(&#39;type&#39;)
.setDescription(&#39;The Type of the crate&#39;)
.setRequired(true)
.addChoices({name: &quot;Normal&quot;, value: &quot;normal&quot;})
.addChoices({name: &quot;Large&quot;, value: &quot;large&quot;})
)
.addStringOption(option =&gt;
option.setName(&#39;item&#39;)
.setDescription(&#39;The item to calculate&#39;)
.setRequired(true)
.addChoices({name: &quot;Melon&quot;, value: &quot;melon&quot;})
.addChoices({name: &quot;Pineapple&quot;, value: &quot;pineapple&quot;})
)
.addIntegerOption(option =&gt;
option.setName(&#39;amount&#39;)
.setDescription(&#39;The amount of the item to calculate&#39;)
.setRequired(true),
),
async execute(interaction) {
const crateSize = interaction.options.getString(&#39;type&#39;);
const item = interaction.options.getString(&#39;item&#39;);
const amount = interaction.options.getInteger(&#39;amount&#39;);
let totalValue = 0;
if (crateSize === &#39;normal&#39;) {
if (item === &#39;melon&#39;) {
totalValue = normalMelonValue * amount;
} else if (item === &#39;pineapple&#39;) {
totalValue = normalPineappleValue * amount;
}
} else if (crateSize === &#39;large&#39;) {
if (item === &#39;melon&#39;) {
totalValue = LargeMelonValue * amount;
} else if (item === &#39;pineapple&#39;) {
totalValue = LargePineappleValue * amount;
}
}
const embed = new MessageEmbed()
.setColor(&#39;#0099ff&#39;)
.setTitle(`Crate Calculated - ${crateSize} ${item} crate`)
.addFields(
{ name: &#39;Amount&#39;, value: `${amount} ${item} crates`, inline: true},
{ name: &#39;Total Value&#39;, value: `$${totalValue}`, inline: true},
)
.setTimestamp()
.setFooter(&#39;calculated successfully&#39;)
await interaction.reply({ embeds: })
},
};

every time I try to fix it when I execute the code I run to this error:

TypeError: MessageEmbed is not a constructor
at Object.execute (C:\Users\Dell\Desktop\bot\commands\fun\crates.js:52:23)
at Object.execute (C:\Users\Dell\Desktop\bot\events\interactionCreate.js:16:18)
at Client.&lt;anonymous&gt; (C:\Users\Dell\Desktop\bot\index.js:35:44)
at Client.emit (node:events:512:28)
at InteractionCreateAction.handle (C:\Users\Dell\Desktop\bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\Dell\Desktop\bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)

i tried fixing it and it wouldn't work i tried what i knew but i always run into this error can you help me?
thanks in advance.

答案1

得分: 1

"MessageEmbed"在新的discordjs中已被替换为"EmbedBuilder",请尝试使用它。

英文:

in the new discordjs MessageEmbed has been replaced by EmbedBuilder try it.

huangapple
  • 本文由 发表于 2023年4月17日 21:28:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035698.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定