An Bùi
An Bùi

Reputation: 1

How to attach file to message in Eris in Discord bot

I have searched everywhere and followed it but it still does not send the message but has a file attached.

if(message.content.startsWith(`${prefix}test`)){
        var content = fs.readFileSync('screenshot.png');
        message.channel.createMessage({content: 'a', file: {"file.name": "a.png", "file.file": content}});
        console.log(content);    
    }

Upvotes: -2

Views: 84

Answers (1)

JustinL
JustinL

Reputation: 295

For your case with a picture file I would suggest using this way:

const { AttachmentBuilder } = require("discord.js");

if(message.content.startsWith(`${prefix}test`)){
        const content = new AttachmentBuilder("{path}/screenshot.png");
        message.channel.createMessage({content: 'a', files: [content]});
        console.log(content);    
}
                    

Upvotes: 0

Related Questions