Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Exium1 opened this issue Jun 25, 2021 · 0 comments
Open

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

Exium1 opened this issue Jun 25, 2021 · 0 comments

Comments

@Exium1
Copy link

Exium1 commented Jun 25, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant