Disable phantom spawning

Minecraft Java Edition

Prevent phantoms from spawning when players do not sleep.

How to do it

  1. Check the edition and version on your Minecraft title screen. This tool supports Java Edition.
  2. Enable cheats in your world or obtain operator permissions on your server.
  3. Choose your version below, copy the command, and paste it into chat using T.

Java 1.21.4 example

/gamerule doInsomnia false

Java 26.3 example (new format)

/gamerule minecraft:spawn_phantoms false

How to undo

/gamerule doInsomnia true

Disables night phantom spawns for players who have not slept. Phantoms did not exist in Java 1.12.2 (added in 1.13).

Other releases, apart from the listed releases, may use different syntax. The interactive form only generates commands for the selected supported version.

Questions & reference

What is the command for "Disable phantom spawning"?

On Java 1.21.4 run /gamerule doInsomnia false; on Java 26.3 run /gamerule minecraft:spawn_phantoms false. Disables night phantom spawns for players who have not slept. Phantoms did not exist in Java 1.12.2 (added in 1.13).

Where do I find my edition and version?

Check your Minecraft title screen. Select the exact supported Java Edition release. Bedrock and unlisted versions may use different syntax: the generator does not assume the closest release.

Why does my command fail?

Enable commands in your own world or obtain operator permissions on a server. Check the edition, version, and complete copied command. Use a command block for a command longer than 256 characters.

Can I get level 1000 enchantments?

The supported Java 26.3, 1.21.4, and 1.20.5–1.20.6 component formats cap enchantments at level 255. Classic NBT in 1.16.5–1.20.4 and 1.12.2 allows different values. Your selected version determines the result.