Tranq
Tranq

Reputation: 47

client.destroy() not working on v12 discord.js

Getting an error while trying to restart the client on discord.js Found this code on this forum, it appears to work normal on the v12 client, but on mine its not working.

I did use before the command console.log to print out the code, and it prints out correct. aswell i generated new token, still not working

the thing what i want is to let it fully restart by an command. on v11 my script worked but this v12 not working anymore.

module.exports.run = async (client, message, args) => {

    if(message.author.id != "43437XXXX068625418") return message.channel.send("You're not bot the owner! https://i.imgur.com/8ep8YbI.gif")

    try {
        message.channel.send("53686XXXX7159040> Attempting a restart...").then(msg => {
          //msg.react('🆗');
          setTimeout(function(){
             msg.edit("53686XXXX7159040> I should be back up now!");
          }, 10000);
        })
        console.log (config.Settings[0].bot_secret_token);
        client.destroy().then(client.login(config.Settings[0].bot_secret_token))
        



          } catch(e) {
            message.channel.send(`ERROR: ${e.message}`)

    }
  }

getting this error,

(node:9432) UnhandledPromiseRejectionWarning: DiscordjsError: Request to use to
en, but token was unavailable to the client.
    at RequestHandler.execute (D:\discordbot2\new\node_modules\discord.js\src\r
st\RequestHandler.js:93:15)
    at RequestHandler.execute (D:\discordbot2\new\node_modules\discord.js\src\r
st\RequestHandler.js:97:19)
    at RequestHandler.push (D:\discordbot2\new\node_modules\discord.js\src\rest
RequestHandler.js:39:25)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:9432) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). To termin
te the node process on unhandled promise rejection, use the CLI flag `--unhandl
d-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejecti
ns_mode). (rejection id: 17)
(node:9432) UnhandledPromiseRejectionWarning: DiscordjsError: Request to use to
en, but token was unavailable to the client.
    at RequestHandler.execute (D:\discordbot2\new\node_modules\discord.js\src\r
st\RequestHandler.js:93:15)
    at RequestHandler.execute (D:\discordbot2\new\node_modules\discord.js\src\r
st\RequestHandler.js:97:19)
    at RequestHandler.push (D:\discordbot2\new\node_modules\discord.js\src\rest
RequestHandler.js:39:25)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:9432) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). To termin
te the node process on unhandled promise rejection, use the CLI flag `--unhandl
d-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejecti
ns_mode). (rejection id: 18)

Upvotes: 1

Views: 1224

Answers (1)

Zsolt Meszaros
Zsolt Meszaros

Reputation: 23161

client.destroy() doesn't return a promise, so you can simply log in again on the next line:

client.destroy()
client.login(config.Settings[0].bot_secret_token)

Upvotes: 1

Related Questions