首页 > 解决方案 > Discord.js bot 没有上线由 Heroku 托管

问题描述

我无法在 heroku 上托管我的机器人。我已经部署了我的机器人,它工作了大约 30 个小时左右。然后我关闭了我的机器人大约 10 个小时,并对我的代码进行了一些重大更改。但是,config.json 和 Procfile 文件保持不变。我尝试了多种方法,例如重新启动worker.1 dyno。我还删除了我的应用程序并重新创建了它。worker: node index.js有人说改成worker: npm startor service: npm start。两者都没有工作。

档案:service: npm start

配置.json:

{
    "mongoPath": "mongodb://localhost:27017",
    "useNewUrlParser": "true",
    "prefix": "$",
    "token": "MY SUPER SECRET TOKEN"
}

包.json:

{
  "name": "discord-bot",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" $$ exit 1",
    "start": "node index.js"
  },
  "repository": {
    "type": "git",
    "url": " "
  },
  "keywords": [],
  "author": "Joel",
  "license": "ISC",
  "dependencies": {
    "cheerio": "^1.0.0-rc.3",
    "discord.js": "^12.4.1",
    "discord.js-tictactoe": "^1.0.2",
    "humanize-duration": "^3.24.0",
    "mongoose": "^5.10.11",
    "ms": "^2.1.2",
    "opusscript": "0.0.7",
    "request": "^2.88.2",
    "wokcommands": "^1.0.1",
    "ytdl-core": "^4.0.0"
  },
  "engines": {
    "node": "14.4.0",
    "npm": "6.14.5"
  }
}

索引.js

//Packages
const Discord = require('discord.js');
const ms = require('ms');
const fs = require('fs');
const ytdl = require('ytdl-core');
const cheerio = require('cheerio');
const request = require('request');
const Duration = require('humanize-duration');
const config = require('./config.json');


//clients
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
const Embed = new Discord.MessageEmbed();
bot.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);

    bot.commands.set(command.name, command);
}


bot.on('ready', () => {
    console.log('ACTIVE!');
});

bot.on('message', (message) => {
    if (!message.content.startsWith(config.prefix) || message.author.bot) return;

    let args = message.content.substring(config.prefix.length).split(' ');
    const command = args.shift().toLowerCase();

    if (command === 'ban') {
        bot.commands.get('pp').execute(message, args, bot);
    } else if (command === 'members') {
        bot.commands.get('pp').execute(message, args, bot);
    } else if (command === 'cls') {
        bot.commands.get('cls').execute(message, args, bot);
    } else if (command === 'ctc') {
        bot.commands.get('ctc').execute(message, args, bot);
    } else if (command === 'cvc') {
        bot.commands.get('cvc').execute(message, args, bot);
    } else if (command === 'echo') {
        bot.commands.get('echo').execute(message, args, bot);
    } else if (command === 'g') {
        bot.commands.get('g').execute(message, args, bot);
    } else if (command === 'gg') {
        bot.commands.get('gg').execute(message, args, bot, Discord, Duration);
    } else if (command === 'help') {
        bot.commands.get('help').execute(message, args, Discord, Duration);
    } else if (command === 'i') {
        bot.commands.get('i').execute(message, args, cheerio);
    } else if (command === 'iq') {
        bot.commands.get('iq').execute(message, args, bot);
    } else if (command === 'kick') {
        bot.commands.get('kick').execute(message, args, bot);
    } else if (command === 'members') {
        bot.commands.get('members').execute(message, args, bot);
    } else if (command === 'pick') {
        bot.commands.get('pick').execute(message, args, bot, Discord);
    } else if (command === 'ping') {
        bot.commands.get('ping').execute(message, args, bot);
    } else if (command === 'pl') {
        bot.commands.get('pl').execute(message, args, bot);
    } else if (command === 'pm') {
        bot.commands.get('pm').execute(message, args, bot);
    } else if (command === 'poll') {
        bot.commands.get('poll').execute(message, args, Embed);
    } else if (command === 'pp') {
        bot.commands.get('pp').execute(message, args, bot);
    } else if (command === 'spam') {
        bot.commands.get('spam').execute(message, args, bot);
    } else if (command === 'status') {
        bot.commands.get('status').execute(message, args, bot);
    } 
});

bot.login(config.token);

日志:

2020-11-04T22:11:10.210494+00:00 heroku[worker.1]: Starting process with command `npm start`
2020-11-04T22:11:10.927608+00:00 heroku[worker.1]: State changed from starting to up
2020-11-04T22:11:13.224071+00:00 app[worker.1]:
2020-11-04T22:11:13.224087+00:00 app[worker.1]: > discord-bot@1.0.0 start /app
2020-11-04T22:11:13.224087+00:00 app[worker.1]: > node index.js
2020-11-04T22:11:13.224088+00:00 app[worker.1]:
2020-11-04T22:11:14.157433+00:00 app[worker.1]: ACTIVE!

如果有人可以帮助我,我将不胜感激。提前致谢!

标签: node.jsherokudiscord.js

解决方案


对不起,我修好了。我再次重新生成了令牌并且它起作用了。


推荐阅读