首页 > 解决方案 > client.destroy() 不适用于 v12 discord.js

问题描述

尝试在 discord.js 上重新启动客户端时出错 在此论坛上找到此代码,它似乎在 v12 客户端上正常工作,但在我的客户端上它不起作用。

我确实在命令 console.log 之前使用过打印出代码,并且打印出正确。我也生成了新令牌,但仍然无法正常工作

我想要的是让它通过命令完全重启。在 v11 上,我的脚本工作了,但这个 v12 不再工作了。

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

    }
  }

收到此错误,

(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)

标签: javascriptnode.jsdiscord.js

解决方案


client.destroy()不返回承诺,因此您只需在下一行再次登录:

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

推荐阅读