This script will switch the Editor Type to IMAGE_EDITOR and set the active image as bpy.data.images['Render Result'].
import bpy
area_type = 'IMAGE_EDITOR'
bpy.context.area.ui_type = area_type # or use (bpy.context.window.screen.areas[5].ui_type = area_type) to change another area to image editor
areas = [area for area in bpy.context.window.screen.areas if area.type == area_type]
area = areas[0]
area.spaces.active.image = bpy.data.images['Render Result']
override = {
'window': bpy.context.window,
'screen': bpy.context.window.screen,
'area': area,
'region': [region for region in area.regions if region.type == 'WINDOW'][0],
}
bpy.ops.image.add_render_slot(override)
bpy.context.area.ui_type = 'IMAGE_EDITOR'to switch to image editor. your code will give poll failed error, see for more info on overriding: https://blender.stackexchange.com/a/270716/142292 – Harry McKenzie Aug 03 '22 at 08:56