Message.reply()
возвращает Обещание , разрешается с другим сообщением . Чтобы использовать отправленное сообщение, вам нужно получить доступ к возвращенному значению. Обратите внимание на scope из restartMsg
в приведенных ниже примерах.
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);
Async / await
эквивалент:
// 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);
}