I'm working on a Discord bot though discord.js; I'm trying to make a command which takes a screenshot of specific websites(logged in) and posts them back in chat. However, I've been unable to find a way to take screenshots.
-
3Does this answer your question? [Using HTML5/Canvas/JavaScript to take in-browser screenshots](https://stackoverflow.com/questions/4912092/using-html5-canvas-javascript-to-take-in-browser-screenshots) – svltmccc Dec 08 '19 at 04:55
-
1Wouldn't that require a browser? The bot is pure js and running through node.js. *I saw this method while searching for ways to implement this. – Junny Dec 08 '19 at 05:17
-
You should add to the question that you are using nodejs only – svltmccc Dec 08 '19 at 05:21
-
You can check this library https://www.npmjs.com/package/screenshot-desktop – svltmccc Dec 08 '19 at 05:22
-
I'll edit the question, sorry for the confusion. – Junny Dec 08 '19 at 05:26
4 Answers
Try Puppeteer, it's a Headless Chrome Node.js API that makes dealing with websites easy. It lets you act like a browser, so you can login with elementHandle .type and elementHandle.click, as well as having a built in screenshot function.
You can see a working examples of Puppeteer at https://try-puppeteer.appspot.com/

- 71
- 6
-
Puppeteer is my recommendation as well however I'm worried this breaks TOS when it comes to self bots. Also would fail captcha... – Strike Eagle Dec 09 '19 at 15:18
Puppeteer is a good solution if you can get it to work. You may run into problems with the captcha and discord TOS when it comes to self bots. One alternative you could try is to make a copy of the CSS styling/format discord uses, then use Puppeteer to generate an identical-looking webpage using the raw data you can get through the typical API.

- 852
- 5
- 19
const discord = require("discord.js");
module.exports.run = async (Client, message, args, prefix) => {
if (!message.content.startsWith(prefix)) return;
const sentence = args.join("+");
let sntnce = message.content.split(" ");
sntnce.shift();
sntnce = sntnce.join(" ");
if (!sentence) return message.reply("**Please specify a search query.**");
let embed = new discord.MessageEmbed()
.setTitle("**You Searched Google**")
.setDescription(
`**Your Search Query:** ${sntnce}\n\n **Search Result** - [Click Here](https://www.google.com/search?q=${sentence}&oq=${sentence}&aqs=chrome.0.69i59l2j0l2j69i60j69i61l2j69i65.1147j0j7&sourceid=chrome&ie=UTF-8)`
)
.setColor("GREEN")
.setFooter(" ");
message.channel.send(embed);
};
module.exports.help = {
name: `google`,
aliases: [],
};

- 5,389
- 4
- 16
- 40
results that include puppeteer
Try searching for results that include puppeteer if you're wanting to stick to Javascript

- 1,505
- 2
- 12
- 29

- 1
- 2