I am looking to send a puppeteer screenshot as attachment to discord.
I’ve been looking to posts that talk about this but nothing helped me
Here’s what I got
const url = interaction.options.getString("url");
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle2' });
const screenshot = await page.screenshot();
await browser.close();
//const image = new AttachmentBuilder(screenshot, { name: "image.png" });
await interaction.channel.send({files: [screenshot]})
await interaction.reply({
content: `done`,
ephemeral: true
});
When I try to build an attachment I get this
TypeError [ReqResourceType]: The resource must be a string, Buffer or a valid file stream.
at resolveFile (E:discord botsbeta-botnode_modulesdiscord.jssrcutilDataResolver.js:105:9)
at MessagePayload.resolveFile (E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresMessagePayload.js:294:41)
at E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresMessagePayload.js:259:85
at Array.map (<anonymous>)
at MessagePayload.resolveFiles (E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresMessagePayload.js:259:56)
at ChatInputCommandInteraction.reply (E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresinterfacesInteractionResponses.js:111:70)
at Object.execute (file:///E:/discord%20bots/beta-bot/src/commands/match.js:289:35)
at async Object.execute (file:///E:/discord%20bots/beta-bot/src/events/interactionCreate.js:17:5) {
code: 'ReqResourceType'
}
and when I send the screenshot directly (like in the code I pasted above) I get this
TypeError: Cannot read properties of undefined (reading 'path')
at findName (E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresMessagePayload.js:277:17)
at MessagePayload.resolveFile (E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresMessagePayload.js:291:31)
at E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresMessagePayload.js:259:85
at Array.map (<anonymous>)
at MessagePayload.resolveFiles (E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresMessagePayload.js:259:56)
at TextChannel.send (E:discord botsbeta-botnode_modulesdiscord.jssrcstructuresinterfacesTextBasedChannel.js:181:50)
at Object.execute (file:///E:/discord%20bots/beta-bot/src/commands/match.js:289:43)
at async Object.execute (file:///E:/discord%20bots/beta-bot/src/events/interactionCreate.js:17:5)
Can somebody tell me what’s wrong ?