I keep forgetting adding a menu entry for this function. It is there, but accessing it is not easy. If you save as GIF or 8-bit BMP, it will reduce color count in the saved file to 256. Or you can try modifying the layer style and add a "Reduce color" step to the style.
Eventually, you can download this and drag and drop it on your toolbar with the scripted operation. It only works on raster layers (naturally).