From Minecraft Wiki
Adds experience to a player.
- Java Edition
xp <amount> [player]
xp <amount>L [player]
experience add <players> <amount> [points|levels][upcoming 1.13]
experience set <players> <amount> [points|levels][upcoming 1.13]
experience query <player> <points|levels>[upcoming 1.13]
- Pocket Edition
xp <amount: int> [player: target]
xp <amount: int>L [player: target]
- amount (PE: amount: int)
- Specifies the amount of experience to give to the player. Must be between 0 and 2,147,483,647 (inclusive, without the commas).
- If an
Lis added to the end, adds levels instead. Levels must be between -2,147,483,648 and 2,147,483,647 (inclusive, without the commas) — negative values remove levels instead of adding them.
- If an
- player (PE: player: target) (optional)
- Specifies the target of the command. If not specified, defaults to the command's executor. Not optional in command blocks.
- Fails if arguments are not specified correctly, or if player fails to resolve to one or more online players.
- On success, adds experience or adds/removes levels. Total experience and levels will not be reduced below 0.
- To give 7 experience to yourself:
experience add @s 7[upcoming 1.13]
- To give 3 levels to Alice:
xp 3L Aliceor
xp add Alice 3 levels[upcoming 1.13]
- To remove all levels from all players:
xp -2147483648L @aor
xp set @a 0+
xp set @a 0 levels[upcoming 1.13]