简体   繁体   English

如何发出重置命令来重新启动我的 discord.js 机器人?

[英]How can i make a reset command to restart my discord.js bot?

I want to make a command so when I do.reset it will reboot/restart the bot.我想发出一个命令,所以当我 do.reset 它将重新启动/重新启动机器人。 I am using Discord.js v12.我正在使用 Discord.js v12。

This bot is a simple moderation bot for a server so I just want a quick command to fix errors that require a quick restart without going into Heroku and restart it from there.这个机器人是一个简单的服务器审核机器人,所以我只想要一个快速命令来修复需要快速重启的错误,而无需进入 Heroku 并从那里重新启动它。

I'd imagine you'd need to call the Heroku API to restart the service.我想您需要调用 Heroku API 来重新启动服务。

https://devcenter.heroku.com/articles/platform-api-reference#dyno-restart https://devcenter.heroku.com/articles/platform-api-reference#dyno-restart

To restart your bot you shall destroy the Client and call the login() method.要重新启动您的机器人,您应该销毁客户端并调用login()方法。

client.destroy();
client.login(process.env.token);

Example:例子:

if (command === "reset") {
    if (message.author.id !== "Your ID Here") return false;
    message.reply("Resetting...");
    client.destroy();
    client.login(process.env.token);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM