【发布时间】:2021-06-03 12:48:45
【问题描述】:
我有一个 bot 命令,它是一个图像抓取工具,它使用 puppeteer。我将 puppeteer 文件下载到我的 VSC(Visual Studio 代码)中,当我从 VSC 终端运行机器人时,图像抓取功能起作用。我可以将我使用的文件提交到 GitHub,然后链接到 Heroku。但是当我尝试在 Heroku 上托管机器人并使用 image scraper 命令时,Heroku 给出 UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! 我还将 puppeteer buildpack 添加到我的 heroku 项目中,这似乎并不能解决问题。我见过的一种解决方案是将 { args: ['--no-sandbox'] } 添加到代码中,但我不确定在哪里添加它。我在哪里可以添加 --no-sandbox,或者是否有其他解决方法?谢谢
图像抓取代码:
var Scraper = require('images-scraper');
const google = new Scraper({
puppeteer: {
headless: true
}
})
module.exports = {
name: 'image',
description: 'sends img to channel',
async execute(client, message, args){
const image_query = args.join(' ');
let rng = Math.round(Math.random()*10)
if(!image_query) return message.channel.send('Unable to find image');
const image_results = await google.scrape(image_query, 100);
message.channel.send(image_results[rng].url);
}
}
【问题讨论】:
标签: heroku visual-studio-code discord.js