send
возвращает обещание , поэтому вам нужно либо .catch
обещание, либо использовать async/await
с блоком try/catch
.
A обещание - это объект, представляющий асинхронную c операцию, поэтому ошибка, возникающая внутри него, не будет перехвачена блоком try / catch.
message.author.send('Here\'s a list of my commands:')
message.author.send('Commands')
message.channel.send('I sent you a dm with all the commands. If you haven\'t received it, check if your dms are open.')
.catch((error) => {
message.channel.send('Couldn\'t send you a message. Are your dms open?')
});
Альтернативный вариант, если вы используете async/await
:
async function whatever() {
...
try {
await message.author.send('Here\'s a list of my commands:')
await message.author.send('Commands')
await message.channel.send('I sent you a dm with all the commands. If you haven\'t received it, check if your dms are open.')
} catch (err) {
await message.channel.send('Couldn\'t send you a message. Are your dms open?')
}
}