如何过滤并修复清除命令代码中的“UnhandledPromisejectionWarning:discordapierror:invalid form body”?

3b6akqbq  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(261)

每当我尝试使用命令时,如 purge 10 这给了我一个错误:

UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
message_reference: Unknown message
UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
message_reference: Unknown message
    at RequestHandler.execute (/home/runner/SD-14-1/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async RequestHandler.push (/home/runner/SD-14-1/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
(node:37) 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:37) [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.

这是我的代码:

async execute(client, message, args, Discord) {
        if (args[1]) {
            return;
        }
        const amount = parseInt(args[0]);

        if (!args.length || isNaN(amount) || amount < 1 || amount > 100) {
            return message.lineReply('\\❌ You need to provide a real number between 1 - 100...');
        }
        await message.delete()
        const messages = await message.channel.messages.fetch({ limit: amount })
        const deletable = messages.filter(m => (m.createdTimestamp - Date.now()) < ms('14d') && !m.pinned && !m.deleted && m.deletable)
        if (deletable.size > 0) {
            await message.channel.bulkDelete(deletable, true)
        }
    }

我是一个初学者,所以,你可能不喜欢我的代码。。。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题