#javascript #node.js #discord.js
#javascript #node.js #discord.js
Вопрос:
Хорошо, в основном я добавил message.delete();
ко всем своим командам в моем боте, потому что я хочу удалить запрос автора для команды.
Все идет нормально, но когда я отправляю боту команду, поскольку он не может удалить сообщение, появляется сообщение об ошибке.
at RequestHandler.execute (c:UsersPascaleDesktopDungeonBotnode_modulesdiscord.jssrcrestRequestHandler.js:170:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
<node_internals>/internal/process/warning.js:32
(node:17772) 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 terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
<node_internals>/internal/process/warning.js:32
(node:17772) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Как мне сделать так, чтобы он просто возвращался и сообщение об ошибке не появлялось??
Ответ №1:
Есть несколько способов справиться с этим. Первым будет бот, игнорирующий вас в DMs, чтобы избежать ошибок:
// detects if the message is sent in dms, returns if so
if (message.channel.type === 'dm') return;
Я предлагаю первое решение, хотя вторым способом было бы использовать try / catch
блок:
try {
message.delete();
} catch {
return;
}