机器人重新启动后,无论如何我有什么方法可以编辑我的消息,我希望他发送一条消息,立即重新启动,重新启动后,它应该将消息编辑为Done:white_checkmark:
console.log(message.author.tag + ' restarted The bot')
message.reply('You restarted the bot, wait a few seconds') // <-- this message should be edited
bot.channels.get("593824605144088586").send(message.author.tag + ' restarted the bot')
bot.channels.get("593824605144088586").send('---------------------------------------------------')
setTimeout(function () { resetBot() }, 5000);
function resetBot() {
restarted = true;
bot.channels.get("593824605144088586").send('Restarting...')
.then(msg => bot.destroy())
.then(() => bot.login(auth.token));
}
答案 0 :(得分:0)
Message.reply()
返回一个Promise,并用另一个Message进行解析。要使用发送的消息,您必须访问返回的值。在下面的示例中注意restartMsg
的{{3}}。
console.log(`${message.author.tag} restarted the bot.`);
message.reply('You restarted the bot, please wait.')
.then(restartMsg => {
const logsChannel = bot.channels.get('593824605144088586');
if (!logsChannel) return console.error('Logs channel missing.');
logsChannel.send(`${message.author.tag} restarted the bot.\n---`)
.then(() => {
setTimeout(() => {
logsChannel.send('Restarting...')
.then(() => bot.destroy())
.then(() => bot.login(auth.token))
.then(() => restartMsg.edit('Restart successful.'));
}, 5000);
});
})
.catch(console.error);
scope等效:
// Asynchronous context (meaning within an async function) needed to use 'await.'
try {
console.log(`${message.author.tag} restarted the bot.`);
const restartMsg = await message.reply('You restarted the bot, please wait.');
const logsChannel = bot.channels.get('593824605144088586');
if (!logsChannel) return console.error('Logs channel missing.');
await logsChannel.send(`${message.author.tag} restarted the bot.\n---`);
setTimeout(async () => {
await logsChannel.send('Restarting...');
await bot.destroy();
await bot.login(auth.token);
await restartMsg.edit('Restart successful.');
}, 5000);
} catch(err) {
console.error(err);
}