所以我的机器人在Heroku上运行良好,并且一直部署到我向js文件中添加一些代码为止。我安装了node-cron和node-schedule,因为我正在处理预定的消息事件。
const Discord = require("discord.js")
const cron = require("node-cron");
const bot = new Discord.Client({disableEveryone: false});
module.exports = bot => {
console.log(`${bot.user.username} is online`)
bot.user.setActivity("SINoALICE", {type: "PLAYING"});
let reminderChannel = client.channel.find(channel => channel.id === '731870214526074910');
let colloseumChannel = client.channel.find(channel => channel.id ==='730423361783726111');
const cronJobs = [
{ "type": "Guerrilla", "param": "* 25 20 * * *" },
{ "type": "Guerrilla", "param": "* 25 22 * * *" },
{ "type": "Guerrilla", "param": "* 25 00 * * *" },
{ "type": "Guerrilla", "param": "* 25 02 * * *" },
{ "type": "Guerrilla", "param": "* 25 04 * * *" },
{ "type": "Guerrilla", "param": "* 25 13 * * *" },
{ "type": "Conquest", "param": "* 25 21 * * *" },
{ "type": "Conquest", "param": "* 25 23 * * *" },
{ "type": "Conquest", "param": "* 25 01 * * *" },
{ "type": "Conquest", "param": "* 25 03 * * *" },
{ "type": "Conquest", "param": "* 25 05 * * *" },
{ "type": "Conquest", "param": "* 50 14 * * *" },
{ "type": "Colloseum", "param": "* 50 22 * * *" }
];
for(let i = 0; i < cronJobs.length; i++){
cron.schedule(cronJobs[i].param, () => {
let message;
if(cronJobs[i].type === 'Colloseum'){
colloseumChannel.send(`@everyone The Colloseum Battle is about to being in 10 minutes. Please ready yourself!`);
} else {
reminderChannel.send(`@everyone The next ${croneJobs.type} Event begins in 5 minutes.`);
}
console.log("Scheduler running...")
})
}
}
在此之后,当我尝试部署分支时,我得到了
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 12.x...
Downloading and installing node 12.18.2...
Using default npm version: 6.14.5
-----> Restoring cache
- node_modules is checked into source control and cannot be cached
-----> Installing dependencies
Prebuild detected (node_modules already exists)
Rebuilding any native modules
> node-cron@2.0.3 postinstall /tmp/build_60d67a8f4743298ef5ee95c5ea225a00/node_modules/node-cron
> opencollective-postinstall
sh: 1: opencollective-postinstall: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! node-cron@2.0.3 postinstall: `opencollective-postinstall`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the node-cron@2.0.3 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.rKNE5/_logs/2020-07-12T20_38_10_922Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- node_modules checked into source control
https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
不确定我需要诚实做些什么。创建文件后,我再也没有碰过它。