Discord.js bot 没有上线由 Heroku 托管
Posted
技术标签:
【中文标题】Discord.js bot 没有上线由 Heroku 托管【英文标题】:Discord.js bot doesn't come online hosted with Heroku 【发布时间】:2021-02-17 15:43:09 【问题描述】:我无法在 heroku 上托管我的机器人。我已经部署了我的机器人,它工作了大约 30 个小时左右。然后我关闭了我的机器人大约 10 个小时,并对我的代码进行了一些重大更改。但是,config.json 和 Procfile 文件保持不变。我尝试了多种方法,例如重新启动worker.1 dyno。我还删除了我的应用程序并重新创建了它。有人说要把worker: node index.js
改成worker: npm start
或者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!
如果有人可以帮助我,我将不胜感激。提前致谢!
【问题讨论】:
“不在线”是什么意思?你的意思是不和谐的状态,因为你的日志表明它确实有效。 另外,请重新生成您的不和谐令牌! 是的,我的意思是状态。但我也意味着所有命令都不起作用。但是,如果我在本地运行它,所有命令都可以工作。 是的,我已经重新生成了 您可以手动设置状态,如果这是您所关心的。您提到您进行了重大更改,您可以在您的onMessage
处理程序中包含什么吗?也许那里的某些东西阻止了命令。
【参考方案1】:
对不起,我修好了。我再次重新生成了令牌并且它起作用了。
【讨论】:
以上是关于Discord.js bot 没有上线由 Heroku 托管的主要内容,如果未能解决你的问题,请参考以下文章
Discord bot 使用 discord.js 不播放 mp3 文件,没有给出错误
从 twitch bot 调用 Discord.js 音乐问题找到语音频道