英文:
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('@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: })
},
};
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.<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 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论