我尝试使用discord.js通过命令发送一些JavaScript对象(作为JSON文件中的JSON数据)。然而,这并不像发送图像那么容易。我尝试使用AttachmentBuilder
(有/没有JSON.stringify
),有和没有额外的数据是名称:
const jsonFile = new AttachmentBuilder(JSON.stringify(data), {
name: embedName + ".json",
});
message.reply({ content: "Data:", files : [jsonFile]})
字符串
但无论我如何输入数据,我都会得到这个奇怪的错误:
TypeError: Cannot read properties of undefined (reading 'Symbol(Symbol.asyncIterator)')
at DataResolver.resolveFile (C:\Users\___\node_modules\discord.js\src\util\DataResolver.js:117:24)
at MessagePayload.resolveFile (C:\Users\___\node_modules\discord.js\src\structures\MessagePayload.js:260:54)
at C:\Users\___\node_modules\discord.js\src\structures\MessagePayload.js:225:85
at Array.map (<anonymous>)
at MessagePayload.resolveFiles (C:\Users\___\node_modules\discord.js\src\structures\MessagePayload.js:225:56)
at StringSelectMenuInteraction.reply (C:\Users\___\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:109:70)
at module.exports.run (C:\Users\___\interactions\StringSelectMenu\select-embed.js:38:20)
at async Object.run (C:\Users\___\events\interactionCreate.js:24:11)
at async SkeeBot.<anonymous> (C:\Users\___\classes\SkeeBot.js:96:11)
型
1条答案
按热度按时间8gsdolmq1#
您需要使用缓冲区将数据流传输到构建器。您可以使用
Buffer.from(<target>)
来完成此操作。您可以了解有关buffers here的更多信息或访问Node.js docs here。使用您的源代码的示例:
字符串