javascript - Image Scraper 将所有附件从单个消息推送到数组
问题描述
我一直在这里使用这个脚本https://github.com/17teen/Discord-Image-Scraper但偶然发现了一个问题,它从包含 5 个附件的单个消息中抓取并将它们作为一个整体拉到 JSON 数组中而不是将它们分成单独的链接,就好像它是每条消息的图像一样。
我已经尝试在两者中使用.replace(',','')
and并且
仍然面临这个问题。.join(',')
post.js
scraper.js
[
"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"
]
解决方案
感谢@MrMythical解决了这个问题。
对于使用此代码的任何人,修复如下:
原始代码是
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}`))
})
改进的代码
添加了解决方案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}`)) })
});
}
推荐阅读
- javascript - 为什么“焦点内”在 Safari 中不起作用
- sql - 在执行之前修改 SELECT 语句
- kubernetes - 为什么 LoadBalancer 服务中的 EXTERNAL-IP 总是挂起?
- authentication - 使用 rabbitmq-auth-backend-http 对 MQTT 和 AMQP 请求进行身份验证的问题
- python - 有没有办法在 Python 的 unittest 框架中自动创建测试用例?
- python - 使用 Python 根据后缀重塑数据框
- python - PyQT5:如何同时使用 QLineEdit:验证器和 InputMask?
- c++ - 指针算术 - 数组和指向数组的指针的问题
- reactjs - 直接在浏览器中输入 URL 时,React 子路径会产生错误
- google-apps-script - MailApp可以画折线图吗?