Using autocode puppeteer this takes a screenshot of a webpage that uses p5.js and then sends it to Discord. The prefix is !p5
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const puppeteer = require('autocode-puppeteer');
const width = 700,
height = 450;
let p5js = `
function setup() {
createCanvas(700, 450);
background(77, 172, 255)
}
function draw() {
noStroke();
fill(70, 168, 50)
rect(0, 350, 700, 450)
fill(196, 212, 19);
circle(500, 100, 100);
fill(92, 61, 30);
rect(50, 200, 250, 150);
fill(117, 89, 61);
strokeWeight(1);
stroke(0);
triangle(25, 215, 180, 100, 325, 215);
rect(75, 300, 30, 50);
fill(189, 191, 54);
circle(83, 330, 10)
fill(255, 255, 255);
noStroke();
square(120, 300, 35);
fill(0, 0, 0);
square(122, 302, 31);
fill(255, 255, 255);
rect(136, 300, 2, 35);
rect(120, 317, 35, 2);
circle(475, 150, 75);
circle(500, 150, 75);
circle(525, 150, 75);
circle(450, 160, 50);
circle(425, 160, 50);
}
`;
let bodyHtml = `
`;
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(bodyHtml);
await page.setViewport({width, height, deviceScaleFactor: 2});
let screenshot = await page.screenshot({
type: 'jpeg',
quality: 90,
fullPage: true,
});
await browser.close();
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
file: Buffer.from(screenshot, 'binary'),
filename: 'image.jpg',
});