简体   繁体   中英

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. I am using 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.

I'd imagine you'd need to call the Heroku API to restart the service.

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

To restart your bot you shall destroy the Client and call the login() method.

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);
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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