Skip to content

Message files do not work with an array of file objects #86

@Exium1

Description

@Exium1

The Problem

When adding files as an array to the createMessage function, files do not display correctly as they contain errors. This happens even though each item in the array is a correct file object that works if sent individually.

Example

Running this function:

msg.channel.createMessage("Some images:", [
	{ file: readFileSync("./assets/images/PauseChamp.png"), name: "PauseChamp.png" },
	{ file: readFileSync("./assets/images/PagChomp.png"), name: "PagChomp.png" }
]);

Returns this:
image
If these files are attempted to be downloaded, a webpage displays, "The image cannot be displayed because it contains errors."

Fix

if (file && Array.isArray(file)) {
    file.forEach(function(f) {
        f.file = Buffer.from(f.file, 'base64');
    });
};

I was able to find a quick fix that allows both images to be sent. This is by adding the previous lines into the files /src/sharding/clustermanager.js and /src/structures/SyncedRequestHandler.js after,

if (file && file.file) file.file = Buffer.from(file.file, 'base64');

and

if (file && file.file) file.file = Buffer.from(file.file).toString('base64');

respectively.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions