Image Scraper 将所有附件从单个消息推送到数组
Posted
技术标签:
【中文标题】Image Scraper 将所有附件从单个消息推送到数组【英文标题】:Image Scraper pushing all attachments from single message to array 【发布时间】:2021-11-25 02:55:33 【问题描述】:我一直在这里使用此脚本https://github.com/17teen/Discord-Image-Scraper,但偶然发现了一个问题,即它从包含 5 个附件的单个消息中抓取并将它们作为一个整体拉到 JSON 数组中,而不是像将它们分成单独的链接一样这是每条消息的图像。
我尝试在post.js
和scraper.js
中使用.replace(',','')
和.join(',')
仍然面临这个问题。
[
"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"
]
【问题讨论】:
试试thatArray[0].split(",")
感谢@MrMythical 的解决方案,成功了。
【参考方案1】:
感谢@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`)) )
);
【讨论】:
以上是关于Image Scraper 将所有附件从单个消息推送到数组的主要内容,如果未能解决你的问题,请参考以下文章
pyfacebook stream.publish 未发布所有详细信息