Asset help for Discord Canvas


I really need help with Canvas Discord requiring files.

(node:3555) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): Error: error while reading from input stream

This is my script :

client.on(‘guildMemberAdd’, async member => {
const channel = member.guild.channels.find(ch => === ‘new-members’);
if (!channel) return;
const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext(‘2d’);

const background = await Canvas.loadImage('./assets/wallpaper.jpg');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
const attachment = new Discord.Attachment(canvas.toBuffer(), 'welcome-image.png');

channel.send(Welcome to the server, ${member}!, attachment);


assets is not really a folder on the server. The assets are stored on a cdn. If you click the asset you can get its URL. An example …

Edit: the number at the end seems optional, possibly used for the cdn analytics to track which project is using it?


The random string is to break any existing browser cache for the asset should you have been using a previous version of the uploaded file.


I think canvas requires the assets to be stored locally in the project. Try uploading the files via the console using wget url_to_file where url_to_file is the URL you get when you click on the file assets.


Thanks everyone, I got it working :slight_smile:


How did you get it working? I executed wget <asset url>, and then reloaded my project. Same error.


It sounds like you imported the image to your root directory. Try following these steps: Assets folder path