1

我正在尝试执行一个命令来删除机器人在频道中的最后 N 条消息。该机器人没有MANAGE_MESSAGES权限。当 N = 1 时,机器人会按预期删除其最新消息。但是,当 N > 1 时,机器人会抛出错误:

D:\Seneca\7th_Term\DPS909\EarTensifier\node_modules\discord.js\src\rest\RequestHandler.js:170
          return reject(new DiscordAPIError(request.path, data, request.method, res.status));
                        ^

DiscordAPIError: Missing Permissions
    at RequestHandler.execute (D:\Seneca\7th_Term\DPS909\EarTensifier\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {      
  method: 'post',
  path: '/channels/757408200973877277/messages/bulk-delete',
  code: 50013,
  httpStatus: 403
}

对我来说奇怪的是,机器人为什么能够删除它的 1 条消息,但不能删除更多?当我在MANAGE_MESSAGES启用的情况下测试相同的代码时,它运行良好。是否可以在未经许可的情况下实现此功能MANAGE_MESSAGES,因为我只希望机器人删除自己的消息,而不是其他人的?

这是我的实现:

const botID = process.env.DISCORD_ID;
if (message.channel.type == 'text') {
    await message.channel.messages.fetch({limit: 100}).then(messages => {
        let botMessages = messages.filter(msg => msg.author == botID).array();
        if (no_of_messages > 0){
            botMessages.splice(no_of_messages);
        }
        message.channel.bulkDelete(botMessages);
        client.log(`Deleted ${botMessages.length} messages from ${botID}`)
    }).catch(err => {
        client.log('Error while doing Bulk Delete');
        client.log(err);
    });
}
4

0 回答 0