javascript - Discord.js 重启命令不起作用(返回未定义的错误)
问题描述
我正在使用 discord.js 制作一个机器人,但我的重启命令不起作用。通过不工作,我的意思是,我得到这个错误:
(node:41784) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_timeouts' of undefined
我的代码是:
const config = require('../../config.json');
module.exports.run = async (bot, message, args) => {
if(!config.owners.includes(message.author.id)) {
return message.channel.send(`Only the bot owner can execute this command`)
}
message.channel.send(`Okay, I'll restart...`)
.then(
bot.destroy
).then(
bot.login(config.token)
)
};
module.exports.help = {
name: "restart",
description: "Restarts the bot",
usage: "restart",
category: "dev"
};
如果可以,请帮忙
解决方案
尝试这个:
const config = require('../../config.json');
module.exports.run = async (bot, message, args) => {
if(!config.owners.includes(message.author.id)) {
return message.channel.send(`Only the bot owner can execute this command`)
}
message.channel.send(`Okay, I'll restart...`)
.then(()=>bot.destroy()) // <<<<
.then(()=>bot.login(config.token)) // <<<<
};
module.exports.help = {
name: "restart",
description: "Restarts the bot",
usage: "restart",
category: "dev"
};
.then()
将函数作为参数,因此您必须将操作包装到函数中。
推荐阅读
- oauth-2.0 - OAuth2 中的“资源所有者密码凭据”是否安全?
- c# - 使用 UI 按钮移动游戏对象
- microservices - 微服务的 API-Gateway 应该部署在哪里?
- reactjs - 在应用程序构建后更改 React 构建路径
- python-3.x - subprocess.check_output 在 python 3 中不起作用,但在 python 2.7 中起作用
- sql - 优化SQL Query,需要建议
- sql - 如何修复oracle中的xml标签
- python - 无法将表单保存到模型 django
- java - 为什么`2.0 - 1.1`和`2.0F - 1.1F`会产生不同的结果?
- python - 如何附加所有细分的多边形坐标?