【问题标题】:client.destroy() not working on v12 discord.jsclient.destroy() 不适用于 v12 discord.js
【发布时间】:2021-06-30 01:21:13
【问题描述】:

尝试在 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)

【问题讨论】:

  • message 来自哪里?
  • Client#destroy() 只需注销机器人并结束与 Discord API 的连接
  • 我知道,但它不起作用......根本没有任何反应。

标签: javascript node.js discord.js


【解决方案1】:

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

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

【讨论】:

  • 当我按照你所说的去做时,什么也没有发生。问候
  • 我收到一条不和谐的确认文本,但客户端没有重新启动或不执行任何操作。仍然存在。@Zsolt Meszaros
  • 好吧,我可以说它仍然不起作用。什么都没发生。客户端根本不会断开连接并重新连接
猜你喜欢
  • 2020-12-25
  • 2020-10-19
  • 2021-08-04
  • 2021-03-26
  • 2021-09-22
  • 2022-01-09
  • 2021-02-10
  • 2021-01-24
  • 2020-12-03
相关资源
最近更新 更多