You can use something like this to get a position snapped to a grid:
var CELL_SIZE = 32 # or whatever
func position_snapped(pos:Vector2):
return (pos / CELL_SIZE).floor() * CELL_SIZE
If you are using a TileMap you can use its maptoworld and worldtomap functions to transform world coordinates into grid positions.