javascript - 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)
解决方案
client.destroy()
不返回承诺,因此您只需在下一行再次登录:
client.destroy()
client.login(config.Settings[0].bot_secret_token)
推荐阅读
- angular - 在 Angular Universal 上使用 Facebook 的 SDK 在移动设备中登录的问题
- reactjs - 这是 React 在调用 api、设置状态和渲染数据时的常见模式吗?
- javascript - 对数组进行排序后,useState 不会重新渲染
- point-clouds - 为什么 pcl 中的 PPFRegistration 工作这么慢
- powershell - 一次 ssh 到多个服务器
- reactjs - Speechly 仅适用于 Android,但不适用于 Apple
- javascript - 拆分字符串值,但将换行符保留在新数组中
- python-3.x - GitHub Actions:pylint 失败并显示 F0001:没有名为 __init__.py 的模块(致命)
- amazon-web-services - 建立一个触发器,每次在 S3 中创建文件时触发,该触发器会生成一个事件,将所需的 SQL 发布到 ClickHouse
- sql - 单行子查询返回多行的情况