wrapText(ctx, textMessage, 10, imgHeight/4 + 10, imgWidth-10, 50) var frame = new MessageAttachment(canvas.toBuffer(), "frame.png"); message.channel.send(frame); function wrapText(context, text, x, y, maxWidth, lineHeight) { var words = text.split(' '); var line = ''; for(var n = 0; n < words.length; n++) { var testLine = line + words[n] + ' '; var metrics = context.measureText(testLine); var testWidth = metrics.width; if (testWidth > maxWidth && n > 0) { context.fillText(line, x, y); context.strokeText(line, x, y); line = words[n] + ' '; y += lineHeight + lineHeight/4; } else { line = testLine; } } context.fillText(line, x, y); context.strokeText(line, x, y); message.delete() }