I've been using this script here https://github.com/17teen/Discord-Image-Scraper but stumbled on an issue where it scrapes from a single message that contains say 5 attachments and pulls them to the JSON array as a whole instead of separating them into individual links as if it was an image per message.
I've tried using .replace(',','') and .join(',') in both post.js and the scraper.js
and still face this issue.
[
"https://media.discordapp.net/attachments/831804312538841088/893067795154231337/IMG_20210930_113200.jpg,https://media.discordapp.net/attachments/831804312538841088/893067795322011668/IMG_20210930_113039.jpg,https://media.discordapp.net/attachments/831804312538841088/893067795535900702/IMG_20210930_112940.jpg,https://media.discordapp.net/attachments/831804312538841088/893067795741437952/IMG_20210930_113006.jpg","EXTRA","EXTRA"
]
Thanks to @MrMythical for the fix solution to the problem.
For anyone using this code, the fix is below:
The original code was
webhookCli.send(link.split(",")).then((msg) => {
spinner.succeed(greenBright(`[${index}] Link Posted: ${yellowBright(msg.content)}`))
}).catch((err) => {
spinner.fail(red(`[${index}] Link failed to post | ${err}`))
})
IMPROVED CODE
Added solution to link
// Settings
const { webHook_id, webHook_token } = require("./settings.json");
const { greenBright, red, grey, yellowBright } = require("chalk");
const ora = require("ora");
const readline = require("readline").createInterface({ input: process.stdin, output: process.stdout });
// Modules
const { WebhookClient } = require("discord.js");
// Webhook
const webhookCli = new WebhookClient(webHook_id, webHook_token);
readline.question(grey("[?] Do you wish to post these links? (Y/N) "), (answr) => {
if (answr === "Y" || answr === "y" || answr === "Yes" || answr === "yes" || answr === "YES") return Post()
if (answr === "N" || answr === "n" || answr === "No" || answr === "no" || answr === "NO") return process.exit(1);
});
/**
* Posts links to a specifed channel
*/
function Post() {
const spinner = ora("Preparing to post").start();
const fetchLinks = require("./links.json")
fetchLinks.forEach((link, index) => {
webhookCli.send(link.split(",")).then((msg) => { spinner.succeed(greenBright(`[${index}] Link Posted: ${yellowBright(msg.content)}`)) }).catch((err) => { spinner.fail(red(`[${index}] Link failed to post | ${err}`)) })
});
}